0
我想刪除一切從一個URL,但域。所以http://i.imgur.com/rA81kQf.jpg成爲imgur.com。parse_url和刪除子域
$url = 'http://i.imgur.com/rA81kQf.jpg';
$parsedurl = parse_url($url);
$parsedurl = preg_replace('#^www\.(.+\.)#i', '$1', $parsedurl['host']);
// now if a dot exists, grab everything after it. This removes any potential subdomain
$parsedurl = preg_replace("/^(.*?)\.(.*)$/","$2",$parsedurl);
上述工作,但我覺得我應該只是一個preg_replace爲此。任何想法如何我可以結合這兩個?
可能重複(HTTP ://stackoverflow.com/questions/2679618/get-domain-name-not-subdomain-in-php) – Federkun
http://stackoverflow.com/questions/16027102/get-domain-name-from-full-url –