Home >Backend Development >PHP Tutorial >php 正则如何匹配2级域名

php 正则如何匹配2级域名

WBOY
WBOYOriginal
2016-06-23 13:59:201216browse


域名状态可能是:
xinwen.xxx.com
xinwen.xxx.cn
xinwen.xxx.net
http://xinwen.xxx.com/

php 如何用正则表达式 preg_replace 得到, xinwen 


回复讨论(解决方案)

(?:http\:\/\/)?([^.]+)\.xxx\.(?:(com|cn|net))

$s=<<<TXTxinwen.xxx.comxinwen.xxx.cnxinwen.xxx.nethttp://xinwen.xxx.com/TXT;preg_match_all('#(^|/)([^/\.]+)\.#m',$s,$ar);print_r($ar[2]);

Array
(
    [0] => xinwen
    [1] => xinwen
    [2] => xinwen
    [3] => xinwen
)

正则都要mark学习  弱项

Statement:
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