Verifying whether the email format is correct can be achieved through the filter_var function.
Function introduction:
filter_var() function filters a variable through the specified filter.
Syntax:
filter_var(variable, filter, options)
Parameter introduction:
variable, (required) specifies the variable to be filtered.
filter, (optional) Specifies the ID of the filter to use. The default is FILTER_SANITIZE_STRING.
options, (optional) Specifies an associative array containing flags/options or a single flag/option. Check the possible flags and options for each filter.
(Free learning video tutorial sharing: php video tutorial)
The verification method is as follows:
<?php function check_email($email) { $result = trim($email); if (filter_var($result, FILTER_VALIDATE_EMAIL)) { return "true"; } else { return "false"; } } echo check_email("111@qq.com")."\n"; echo check_email("abc#example.com")."\n";
Here we created a check_email method , used to determine whether the email is qualified. Returns true if qualified, false otherwise.
The output is as follows:
true false
Recommended related article tutorials: php tutorial
The above is the detailed content of Use php to verify whether the email format is correct. For more information, please follow other related articles on the PHP Chinese website!