Archive

Posts Tagged ‘programming’

PHP script to get domain from URL string

May 6th, 2009 admin No comments

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

Categories: technology Tags: ,