PHP 正则后瞻 匹配是否是域名,准确率99.99%
来源:互联网 发布:天津天狮网络主打歌曲 编辑:程序博客网 时间:2024/05/16 15:57
/^([a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?\.)?[a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?(\.us|\.tv|\.org\.cn|\.org|\.net\.cn|\.net|\.mobi|\.me|\.la|\.info|\.hk|\.gov\.cn|\.edu|\.com\.cn|\.com|\.co\.jp|\.co|\.cn|\.cc|\.biz)$/i
匹配网址:
/** * @author Default7 <default7@zbphp.com> * @description 匹配 * t.cn 正确 * t-.cn 错误 * tt.cn正确 * -t.cn 错误 * t-t.cn 正确 * tst-test-tst.cn 正确 * tst--tt.cn -- 错误 * * * * @param $domain * * @return bool */ public function isDomain($domain) { return !empty($domain) && strpos($domain, '--') === false && preg_match('/^([a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?\.)?[a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?(\.us|\.tv|\.org\.cn|\.org|\.net\.cn|\.net|\.mobi|\.me|\.la|\.info|\.hk|\.gov\.cn|\.edu|\.com\.cn|\.com|\.co\.jp|\.co|\.cn|\.cc|\.biz)$/i', $domain) ? true : false; }如果有问题bug,欢迎指正 by default7#zbphp.com
第二种写法:
/** * @param string $str * * @return bool */ public static function isDomain($str = '') { return !empty($str) && !preg_match('/^-|-$|--|-\.|\.-/', $str) && preg_match('/^([\w-]+\.)?[\w-]+' . self::RegExpSuffix() . '$/', $str) ? true : false;// return !empty($str) && strpos($str, '--') === false && preg_match('/^(([a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?\.)?[a-z0-9]+([a-z0-9-]*(?:[a-z0-9]+))?' . self::RegExpSuffix() . ')$/i', $str) ? true : false; } /** * @return mixed */ public static function RegExpSuffix() { return '(' . str_replace('.', '\.', implode('|', self::allowDomainSuffix())) . ')'; } /** * @description 允许的扩展名 * @return array */ public static function allowDomainSuffix() { $arr = array( '.com', '.com.cn', '.cn', '.net', '.net.cn', '.org', '.org.cn', '.gov.cn', '.hk', '.cc', '.info', '.biz', '.mobi', '.us', '.me', '.co', '.co.jp', '.edu', '.tv', '.la', ); sort($arr); return array_unique(array_reverse($arr)); }
0 0
- PHP 正则后瞻 匹配是否是域名,准确率99.99%
- 判断是否是域名的正则表达式
- android 正则表达式 匹配是否是手机号
- 是否匹配 正则(PHP代码函数)
- 匹配域名正则
- 根域名匹配正则
- 正则表达式匹配域名
- PHP正则匹配网址(URL)中主域名写法
- PHP正则匹配网址(URL)中主域名写法
- PHP 检测字符串的编码是否是UTF-8编码的函数 check_utf8() 准确率最高的!
- php 正则判断是否是手机号码 最新
- php 正则判断是否是手机号码
- php 正则判断是否是手机号码 最新
- php 正则判断是否是手机号码
- C#域名操作,正则匹配域名
- 匹配域名的正则表达式
- 正则表达式-匹配IP、域名
- php 正则表达式匹配(输出是否匹配以及匹配值) preg_match
- Spring 注解@Transactional
- Button实现OnClickListener事件的三种方法
- 互联网企业是时候甩掉你的测试部门啦!(How google test software读书笔记)
- ORM 和 Hibernate
- UVa11858 - Frosh Week(树状数组求逆序数)
- PHP 正则后瞻 匹配是否是域名,准确率99.99%
- 使用Jquery EasyUi常见问题解决方案
- linux top命令详解
- JAVA反射机制
- Linux 性能监控、测试、优化工具
- PopupWindow在android中的使用分析
- libevent.org
- Max Sum in circularly situated Values
- 快排的改进算法