Possible Duplicate:
PHP REGEX: Get domain from URL
I am working on a project and it need to select only main url such as from http://domain.com/link/project/domain/index.php i need to select only domain.com
Possible Duplicate:
PHP REGEX: Get domain from URL
I am working on a project and it need to select only main url such as from http://domain.com/link/project/domain/index.php i need to select only domain.com
Try $_SERVER['SERVER_NAME']
, should give you what you are looking for.
$myurl = "http://domain.com/link/project/domain/index.php";
// get domain name
preg_match("/^(http[s]?:\/\/)?([^\/]+)/i", $myurl, $domain_only);
$host = $domain_only[2];
echo "Domain Name is: " . $host;