note 110024 deleted from function.ip2long by danbrown
| From: | danbrown@php.net | Date: | Wed, 12 Sep 2012 17:41:01 +0000 |
| Subject: | note 110024 deleted from function.ip2long by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190674@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Re: hanguofeng at gmail dot com http://www.php.net/manual/en/function.ip2long.php#102898
<?
function check_ip($needle, $haystack_array) {
foreach($haystack_array as $a) {
$a = str_replace('.', '\.', $a);
$a = str_replace('*','[0-9]+', $a);
if(preg_match("/^{$a}$/", $needle) return true;
}
return false;
}
$filter = check_ip('126.1.0.2',
array(
'127.0.0.1',
'172.0.0.*',
'173.0.*.*',
'126.1.0.0/255.255.0.0',
'125.0.0.1-125.0.0.9',
));
?>
"Sometimes, the elegant implementation is just a function. Not a method. Not a class. Not a
framework. Just a function. " -- John Carmack