php 检查电子邮件函数(自写)

yipeiwu_com6年前PHP代码库

复制代码 代码如下:

function is_valid_email_address($email){
$qtext = '[^//x0d//x22//x5c//x80-//xff]';
$dtext = '[^//x0d//x5b-//x5d//x80-//xff]';
$atom = '[^//x00-//x20//x22//x28//x29//x2c//x2e//x3a-//x3c'.
'//x3e//x40//x5b-//x5d//x7f-//xff]+';
$quoted_pair = '//x5c[//x00-//x7f]';
$domain_literal = "//x5b($dtext|$quoted_pair)*//x5d";
$quoted_string = "//x22($qtext|$quoted_pair)*//x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(//x2e$sub_domain)*";
$local_part = "$word(//x2e$word)*";
$addr_spec = "$local_part//x40$domain";
return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}

相关文章

PHP通过调用新浪API生成t.cn格式短网址链接的方法详解

本文实例讲述了PHP通过调用新浪API生成t.cn格式短网址链接的方法。分享给大家供大家参考,具体如下: 新浪提供了长链接转为短链接的API,可以把长链接转为 t.cn/xxx 这种格式...

PHP弹出提示框并跳转到新页面即重定向到新页面

这两天写一个demo,需要用到提示并跳转,主要页面要求不高,觉得没必要使用AJAX,JS等,于是研究了下怎么在PHP提示并跳转。 开始先是用了下面这种: 复制代码 代码如下: echo...

php自定义函数截取汉字长度

复制代码 代码如下: function msubstr($str,$start,$len) { $strlen=$start+$len; for($i=0;$i<$strlen;$...

PHP获得数组交集与差集的方法

本文实例讲述了PHP获得数组交集与差集的方法。分享给大家供大家参考。具体分析如下: 一、数组的交集 array_intersect() array_intersect()函数返回一个保留...

关于PHP堆栈与列队的学习

在PHP中数组常被当作堆栈(后进先出:LIFO)与队列(先进先出:FIFO)结构来使用。PHP提供了一组函数可以用于push与pop(堆栈)还有shift与unshift(队列)来操作数...