使用PHP中怎么对常用的邮箱进行判断

使用PHP中怎么对常用的邮箱进行判断

这篇文章给大家介绍使用PHP中怎么对常用的邮箱进行判断,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

代码如下:


/**
* @todo 用户输入安全性检测
* @param $inputString 用户输入信息
* @return true/false
* @final 可以根据自己的需求进行过滤内容的变换
*/
public function checkUserInput($inputString){
if (strpos('script', $inputString)!=false){//检测是否含有script脚本
return FALSE;
}else if (strpos('iframe', $inputString)!=false){//检测是否含有iframe框架
return FALSE;
}else {
return TRUE;
}
}

/**
* @todo checkeemail
* @param emailString
* @return false/true
*/
public function checkEmail($emailString){
if ($this -> checkUserInput($emailString) === TRUE){//检测是否含有敏感词汇
if (strpos('@', $emailString) != FALSE){//检测是否存在@字符
$emailArr = explode('@', $emailString);
if (count($emailArr) > 2){//检测是否存在多个@字符
return FALSE;
}else{
if (in_array('@'.$emailArr[1], Yii::app() -> params['mail_suffix'])){//检测后缀是否满足日常常用邮箱后缀
return TRUE;
}else{
return FALSE;
}
}
}else{
return FALSE;
}
}else{
return FALSE;
}
}


其中我定义了一个常用邮箱的后缀的数组,具体如下:

//常用邮箱后缀,根据具体需求可以再增加

复制代码 代码如下:


'mail_suffix'=>array('@hotmail.com',
'@msn.com',
'@yahoo.com',
'@gmail.com',
'@aim.com',
'@aol.com',
'@mail.com',
'@walla.com',
'@inbox.com',
'@126.com',
'@163.com',
'@sina.com',
'@21cn.com',
'@sohu.com',
'@yahoo.com.cn',
'@tom.com',
'@qq.com',
'@etang.com',
'@eyou.com',
'@56.com',
'@x.cn',
'@chinaren.com',
'@sogou.com',
'@citiz.com',
),

关于使用PHP中怎么对常用的邮箱进行判断就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。