<?php
function esip($ip_addr)
{
//first of all the format of the ip address is matched
if(preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$ip_addr))
{
//now all the intger values are separated
$parts=explode(".",$ip_addr);
//now we need to check each part can range from 0-255
foreach($parts as $ip_parts)
{
if(intval($ip_parts)>255 || intval($ip_parts)<0)
return FALSE; //if number is not within range of 0-255
}
return TRUE;
}
else
return FALSE; //if format of ip address doesn't matches
}
function domain($domainb)
{
$bits = explode('/', $domainb);
if ($bits[0]=='http:' || $bits[0]=='https:')
{
$domainb= $bits[2];
} else {
$domainb= $bits[0];
}
unset($bits);
$bits = explode('.', $domainb);
$idz=count($bits);
$idz-=3;
if (strlen($bits[($idz+2)])==2) {
$url=$bits[$idz].'.'.$bits[($idz+1)].'.'.$bits[($idz+2)];
} else if (strlen($bits[($idz+2)])==0) {
$url=$bits[($idz)].'.'.$bits[($idz+1)];
} else {
$url=$bits[($idz+1)].'.'.$bits[($idz+2)];
}
return $url;
}
$address='clients1.sub3.google.co.uk';
$parsed_url = parse_url($address);
$check = esip($parsed_url['host']);
$host = $parsed_url['host'];
if ($check == FALSE){
if ($host != ""){
$host = domain($host);
}else{
$host = domain($address);
}
}
echo $host;
Warning: Undefined array key "host" in /in/EhD5r on line 48
Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /in/EhD5r on line 5
Warning: Undefined array key "host" in /in/EhD5r on line 49
google.co.uk
Output for 8.0.0 - 8.0.30
Warning: Undefined array key "host" in /in/EhD5r on line 48
Warning: Undefined array key "host" in /in/EhD5r on line 49
google.co.uk