Reputation: 1559
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? :)
Upvotes: 0
Views: 551
Reputation: 89557
Try this which removes all that begin with www
until the first dot (inclusive):
$Dominio = preg_replace('~^www[^.]*\.~', '', parse_url($EnlaceUrl,PHP_URL_HOST));
Upvotes: 2
Reputation: 99254
Yet another preg_match example :
if(preg_match("/(?:([^.]+).)?([^.]+).([^\\/]+)/", $Dominio, $m)) {
$Dominio = $m[2] . '.' $m[3];
}
Upvotes: 0
Reputation: 27874
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.
Upvotes: 1