$str ='http://www.abc.com/news_id=79';
$url = parse_url($str);
preg_match('/([a-zA-Z]+\.)?(.*?)\.com/',$url['host'],$match);
echo $match[2]
$url = parse_url($str);
preg_match('/([a-zA-Z]+\.)?(.*?)\.com/',$url['host'],$match);
echo $match[2]
调试欢乐多
$ht=parse_url($url);
$host=$ht['host'];
$position=strpos($host,'b');
$str=substr($host,$position-1,3);
echo'$str';我想这样差不多了吧
用parse_url函数把url拆解开,然后去取,这样效率会高很多.
$a=explode('.','$websit');
把字符用'.'分开不知道可以不!!
倒数第一个点前的
用parse_url函数把url拆解开,然后去取,这样效率会高很多.-----
感觉这个函数parse_url也是用正则的方法拆解的。