Home > Article > Backend Development > Email address in php regular string e-mail_PHP tutorial
If you are verifying your email, the first one is good. If you want to get whether there is an email address in an article or string, you can use the second one.
*/
function funcemail($str)//Mailbox regular expression
{
return (preg_match('/^[_.0-9a-z-a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/' ,$str))?true:false;
}
/*
PHP tutorial filter_sanitize_email filter
The filter_sanitize_email filter removes all illegal e-mail characters from a string.
This filter allows all characters, numbers, and $-_.+!*'{}|^~[]`#%/?@&=.
*/
$var="some(one)@example.com";
var_dump(filter_var($var, filter_sanitize_email));
//string(19) "someone@example.com"