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程序

一、安全 无论程序写的如何,首先安全是第一位的,没有安全保障的程序根本不能谈高质量。 二、稳定 无论你代码写的再烂,必须要能稳定运行。 三、用户体验 用户的体验直接决定着一个程序的命运,...

php 分库分表hash算法

复制代码 代码如下://分库分表算法 function calc_hash_db($u, $s = 4) { $h = sprintf("%u", crc32($u)); $h1 = i...

PHP中实现Bloom Filter算法

<?php /*Bloom Filter算法来去重过滤。 介绍下Bloom Filter的基本处理思路:申请一批空间用于保存0 1信息,再根据一批哈希函数确定元素...

php 将字符串按大写字母分隔成字符串数组

alert("createTechBook".split(/(?=[A-Z])/)) 谢了啊 复制代码 代码如下: <?php $str="abcDefGhi"; /* preg_...

php中关于换行的实例写法

在编写PHP脚本代码的时候,我们经常会看到\n和<br/>这两个字符,它们都有换行的作用,那么到底有什么区别呢? 1.\n是使源代码换行,而浏览器显示的内容不换行;...