@ 2014-08-28T08:06:08Z <?php
$testArray = array(
'sub1.sub2.example.co.uk',
'sub1.example.com',
'example.com',
'sub1.sub2.sub3.example.co.uk',
'sub1.sub2.sub3.example.com',
'sub1.sub2.example.com'
);
foreach($testArray as $k => $v)
{
echo $k." => ".extract_domain($v)."\n";
}
function extract_domain($domain)
{
if(preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", $domain, $matches))
{
return $matches['domain'];
} else {
return $domain;
}
}
function extract_subdomains($domain)
{
$subdomains = $domain;
$domain = extract_domain($subdomains);
$subdomains = rtrim(strstr($subdomains, $domain, true), '.');
return $subdomains;
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 4.3.3 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 0 => example.co.uk
1 => example.com
2 => example.com
3 => example.co.uk
4 => example.com
5 => example.com
Output for 4.3.0 - 4.3.2 Notice: Undefined index: domain in /in/JkNf2 on line 20
0 =>
Notice: Undefined index: domain in /in/JkNf2 on line 20
1 =>
Notice: Undefined index: domain in /in/JkNf2 on line 20
2 =>
Notice: Undefined index: domain in /in/JkNf2 on line 20
3 =>
Notice: Undefined index: domain in /in/JkNf2 on line 20
4 =>
Notice: Undefined index: domain in /in/JkNf2 on line 20
5 =>
preferences:dark mode live preview
216.86 ms | 402 KiB | 326 Q