Find out the subdomain part of a domain
Use this code to find the subdomain part of a domain.
function SubdomainGet ($domain) {
// Domain has to be formatted WITHOUT the "http://" part
// eg.
// $domain = 'mydomain.com';
$server_address = $_SERVER['HTTP_HOST'];
// Strip the domain and leave the subdomain
$sub_domain = str_replace("." . $domain, "", $server_address);
if ($sub_domain == $server_address) {
$sub_domain = '';
}
return $sub_domain;
}
You could use it like this:
$subdomain = SubdomainGet('example.com');
Leave a comment