if(substr_count($original_url, 'http://')) {
if(substr_count($original_url, 'www.')) {
// url style would be 'http://www.abc.xxx/page?param' or http://www.abc.xxx.xx/page?param
// extract 'abc'
$temp = explode('.', $original_url);
$store_url = $temp[1];
// now
// $temp[2] = xxx or xxx/page?param
// $temp[3] = null or xx/page?param
//if ($temp[3] == null) { // then we are sure that $temp[2]== "xxx/page?param"
if(sizeof($temp) > 3) {
// extract "xxx" from "xxx/page?param" and append to store url so it will be "abc.xxx"
$temp = explode('/',$temp[2]);
$store_url .= '.'.$temp[0];
}
else {
// then we are sure that $temp[2]== "xxx" and then $temp[3] == "xx/page?param"
// or $temp[2]== xxx/page?stripped-link from second dot(.)
if(substr_count($temp[2], '/')) { // in case $temp[2]== xxx/page?stripped-link from second dot(.)
// extract "xxx" from "xxx/page?stripped-link" and appent to store url so it will be "abc.xxx"
$temp = explode('/',$temp[2]);
$store_url .= '.'.$temp[0]; // "abc".="xxx" ==> abc.xxx
}
else { // in case $temp[2]== "xxx" and then $temp[3] == "xx/page?param"
$store_url .= '.'.$temp[2]; // "abc".="xxx" ==> abc.xxx
// extract "xx" from "xx/page?param" and appent to store url so it will be "abc.xxx.xx"
$temp = explode('/',$temp[3]);
if(strlen($temp[0])==2) {
$store_url .= '.'.$temp[0];
}
}
}
}
else {
// url style would be 'http://abc.xxx/page?param' or 'http://abc.xxx.xx/page?param'
// remove 'http://'
$temp = substr($original_url, 7);
// now temp would be either 'abc.xxx/page?param' or 'abc.xxx.xx/page?param'
// explode with '/'
$temp = explode('/', $temp);
$store_url = $temp[0];
}
}
else if(substr_count($original_url, 'www.')) {
// url style would be 'www.abc.xxx/page?param' or 'www.abc.xxx.xx/page?param'
// remove 'www.'
$temp = substr($original_url, 4);
// now, $temp would be either "abc.xxx/page?param" or "abc.xxx.xx/page?param"
// explode with '/'
$temp = explode('/', $temp);
$store_url = $temp[0];
}
else {
// url style would be 'abc.xxx/page?param' or 'abc.xxx.xx/page?param'
//explode with '/'
$temp = explode('/', $original_url);
$store_url = $temp[0];
}
fonte
2013-07-29 05:27:39
cura da condividere ?? – ramo
come su quello che inizia "Ecco un metodo per ottenere il nome REALE di un dominio". –
Vedi: http://stackoverflow.com/questions/288810/get-the-subdomain-from-a-url – duskwuff