Home >php教程 >php手册 >php使用正则取得域名地址

php使用正则取得域名地址

WBOY
WBOYOriginal
2016-06-21 08:57:311176browse

比如域名是alixixi.com,正则表达式如下:

 

$S = 'http://www.alixixi.com/'
$domain = array('com','cn','name','org','net');
$SS = $S;
$dd = implode('|',$domain);
$SS = preg_replace('/(.*)((\w+)(\.('.$dd.'))*\.('.$dd.'))$/iU','$2',$SS);
echo $SS ;



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