Actually I am trying to get the sub-domain URL using php. I write code below:
$sub_url = explode('.', $_SERVER['HTTP_HOST']);
$suburl = $sub_url[0];
For Example:
if sub domain URL is like my.example.com
the code above is giving me my which is good but if there is no sub domain then my code will return example which is not good.
I want anything before the first dot even www but if there is nothing like if URL is example.com then I want a blank value instead of example.
if (count($sub_url) > 2)? Keep in mind,one.two.three.domain.comcould also occur.