Home  >  Article  >  php教程  >  php 正则字符串中邮箱地址e-mail

php 正则字符串中邮箱地址e-mail

WBOY
WBOYOriginal
2016-06-13 11:18:401005browse

 

如果你是验证邮箱第一个不错,如果你要获取文章或字符串中是否有邮箱地址,可以用第二个.
*/
function funcemail($str)//邮箱正则表达式
{
 return (preg_match('/^[_.0-9a-z-a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$str))?true:false;
}

/*
php教程 filter_sanitize_email 过滤器
filter_sanitize_email 过滤器删除字符串中所有非法的 e-mail 字符。

该过滤器允许所有的字符、数字以及 $-_.+!*'{}|^~[]`#%/?@&=。

*/

$var="some(one)@example.com";

var_dump(filter_var($var, filter_sanitize_email));

//string(19) "someone@example.com"


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn