php 正则如何匹配2级域名

WBOY
Release: 2016-06-23 13:59:20
Original
1178 people have browsed it


域名状态可能是:
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]);
Copy after login

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

正则都要mark学习  弱项

source:php.cn
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template