How to get domain name from any URL in php ?
Tuesday, February 16, 2010 20:46Posted in category PHP Interview Questions
No Comments
function getOnlyDomain($url)
{
$myurl = ereg_replace('www\.','',$url);
$domain = parse_url($myurl);
if(!empty($domain["host"])){
return $domain["host"];
} else {
return $domain["path"];
}
}//end funciton
echo getOnlyDomain('http://www.imjan.com/php-interview-questions/using-php-curl-to-read-and-write-rss-feed-xml/');
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.


