Ok I am writing a CMS that can be used on multiple sites with one back end right now. I am working on my function to verify and get the hostname from the URL. Some of our domains though look like any of these:
www.domain.com
domain.com
sb78392kjnds.members.domain.com <-- with newton for members areas
members.domain.com
the one with the newton always starts with sb followed by 9 numbers and letters
Here is my function I am using to extract the hostname better.
function get_hostname($hostname) {
// Check the url for a newton
$find_newton = preg_match('^(sb[A-z0-9]{9})^', $hostname);
// If the newton exists cut it and recreate url
if ($find_newton == 1) {
$true_host = preg_replace('^(sb[A-z0-9]{9})\.+|members.|^', '', $hostname);
} else {
$find_www_host = preg_match('|www.|', $hostname);
$find_members_host = preg_match('|members.|', $hostname);
if ($find_www_host==1) {
$true_host = preg_replace('|www.|', '', $hostname);
} else if ($find_members_host==1) {
$true_host = preg_replace('|members.|', '', $hostname);
} else {
$true_host = $hostname;
}
}
echo $true_host;
}
is there a better way to do this? If so please point me in the correct direction