用于验证域白名单的脚本

I have easy question. I need to verify a string and validate a whitelist domain like this:

$WList = array('mega.co.nz','mediafire.com','putlocker.com','');
$Dominio = str_replace("www.","",parse_url($EnlaceUrl,PHP_URL_HOST));
if(in_array($Dominio,$WList)){//ok}

but this method doesnt retieve me domains like:

www42.zippyshare.com,www51.zippyshare.com,www71.zippyshare.com,www23.zippyshare.com

how resolve this problem? :)

Try this which removes all that begin with www until the first dot (inclusive):

$Dominio = preg_replace('~^www[^.]*\.~', '', parse_url($EnlaceUrl,PHP_URL_HOST));

You can use this:

if (preg_match('/[\w\d-]+\.(\w{3,4}|(\w{2,3}\.\w{2}))$/', $Dominio, $match))
    $Dominio = $match[1];

It will convert anything.domainname.suffix into domainname.suffix so you can test against your list.

Yet another preg_match example :

if(preg_match("/(?:([^.]+).)?([^.]+).([^\\/]+)/", $Dominio, $m)) {
    $Dominio = $m[2] . '.' $m[3];
}