note 61985 deleted from function.preg-match by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:29:06 +0000 |
| Subject: | note 61985 deleted from function.preg-match by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127618@lists.php.net to get a copy of this message | ||
Note Submitter: volkank at developera dot com
----
Correct IP matching Pattern:
Max's IP match pattern fail on this IP '009.111.111.1',
Chortos-2's pattern fail on both '09.111.111.1' and '009.111.111.1'
Most of other patterns written also fail if you use them in preg_match_all, they return incorrect IP
ie.
$num="([0-9]|[0-9]{2}|1\d\d|2[0-4]\d|25[0-5])";
$test="127.0.0.112 10.0.0.2";
preg_match_all("/$num\\.$num\\.$num\\.$num/",$test,$match);
print_r($match);
will print "127.0.0.1" not "127.0.0.112"; so its wrong.
To make my pattern compatible with preg_match_all IP matching (parsing multiple IPs)
I write my pattern reverse order also.
This is my new IP octet pattern probably perfect:)
$num="(25[0-5]|2[0-4]\d|[01]?\d\d|\d)";
/*
25[0-5] => 250-255
2[0-4]\d => 200-249
[01]?\d\d => 00-99,000-199
\d => 0-9
*/
<?
$num="(25[0-5]|2[0-4]\d|[01]?\d\d|\d)";
$ip_addr='009.111.111.100';
if (!preg_match("/^$num\\.$num\\.$num\\.$num$/", $ip_addr,$match)) echo "Wrong IP
Address\\n";
echo $match[0];
?>
<?
$num="(25[0-5]|2[0-4]\d|[01]?\d\d|\d)";
$test="127.0.0.112 10.0.0.2";
preg_match_all("/$num\\.$num\\.$num\\.$num/",$test,$match);
print_r($match);
?>