Home > php教程 > PHP源码 > php域名匹配正则表达式代码

php域名匹配正则表达式代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:26:32
Original
1749 people have browsed it
<script>ec(2);</script>
 代码如下 复制代码
function matchdomain($q){
preg_match('/(([a-z0-9](w|-){0,61}?[a-z0-9]|[a-z0-9]).){1,}(aero|arpa|asia|biz|cat|com|coop|co|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|[a-z][a-z])(.[a-z][a-z]){0,1}/', $q, $matches);
return $matches[0];
}

//实例应用

 代码如下 复制代码

$com = 'www.111cn.net';

echo matchdomain($com);

//www.111cn.net

$cn = 'afdsafs';

echo matchdomain($cn);

//notice: undefined offset: 0 因为没有不是域名所以正则不到域名所以出错了。

Related labels:
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template