if (filter_var($ip_a, FILTER_VALIDATE_IP)) { echo "This ($ip_a) IP address is valid."; }else{ echo "This ($ip_a) IP address is invalid."; } if (filter_var($ip_b, FILTER_VALIDATE_IP)) { echo "This ($ip_b) IP address is valid."; }else{ echo "This ($ip_b) IP address is invalid."; }
if (!filter_var($invalid_email, FILTER_VALIDATE_EMAIL)) { $sanitized_email = filter_var($invalid_email, FILTER_SANITIZE_EMAIL); echo "This ($invalid_email) email address is invalid."; echo "Sanitized Email is: $sanitized_email"; }
//输出以下内容: This ((corrupted@foo dot com)) email address is invalid. Sanitized Email is: corrupted@foo.com 过滤 GET 和 POST 变量 复制代码 代码如下:filter_input(input_type, variable, filter, options)