<?php
function get_sub_domain(){
preg_match("/(([a-z0-9\-]+\.)*)([a-z0-9\-]+)\.([a-z]{3,4}|[a-z]{2,3}\.[a-z]{2})(\:[0-9]+)?$/", $_SERVER['HTTP_HOST'], $matches);
$sub_domain = null;
if($matches[1]) {
$sub_domain = substr($matches[1], 0, -1);
}
return $sub_domain;
}
?>