PHP script to get domain from URL string

Sometimes maybe you need to get a domain name from a URL string. Here is the code

1
2
3
4
5
6
7
8
9
10
11
12
function GetDomain($url)
{
$nowww = ereg_replace(’www.,,$url);
$domain = parse_url($nowww);
if(!empty($domain["host"]))
    {
     return $domain["host"];
     } else
     {
     return $domain["path"];
     }
}

source

Leave a Reply

Your email address will not be published. Required fields are marked *