我编写了一个函数来验证给定的URL是否是子域URL。
<?php
header("Content-Type: text/plain");
function isSubDomain($myDomain)
{
$myDomain=parse_url($myDomain)["host"];
if(strstr($myDomain,'.',true)=='www')
{
return 0;
break;
}
$domainExtentions=array(
'.com',
'.net',
'.org',
'.co.uk'
);
foreach($domainExtentions as $extention)
{
if($extention==substr($myDomain,-(strlen($extention))))
{
$mydomain=substr($myDomain,0,-(strlen($extention)));
}
}
if (substr_count($mydomain,'.')>0)
{
return 1;
}
}
//Sub-domain exists
if(isSubDomain('http://SUBDOMAIN.hezi-gangina.com/pua/pug/index.php?q=balataLeStus'))
{
echo'This url contains sub-domain!';
echo "\r\n";
}
else
{
echo'This url doesn\'t have any sub-domain!';
echo "\r\n";
}
//No subdomain (www)
if(isSubDomain('http://www.hezi-gangina.com/pua/pug/index.php?q=haMetrixHeshbon'))
{
echo'This url contains sub-domain!';
echo "\r\n";
}
else
{
echo'This url doesn\'t have any sub-domain!';
echo "\r\n";
}
//Non www url (and no sub-domain)
if(isSubDomain('http://hezi-gangina.com/pua/pug/index.php?q=einLehaSikuy'))
{
echo'This url contains sub-domain!';
echo "\r\n";
}
else
{
echo'This url doesn\'t have any sub-domain!';
echo "\r\n";
}看起来工作得很完美(而且应该完全更新域扩展),这就带来了问题.
发布于 2015-01-28 00:41:38
如果你在".“号爆炸了呢?您可以查看最后一个部分是否是.co,以确定扩展是否是一个或两个部分长。您可以查看第一部分,看看它是否是www,然后对这些部分进行计数,就可以知道它是否是子域。
https://stackoverflow.com/questions/28182057
复制相似问题