note 52836 added to function.preg-match
| From: | Chortos-2 at osu1 dot php dot net | Date: | Sat, 14 May 2005 08:30:19 +0000 |
| Subject: | note 52836 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89406@lists.php.net to get a copy of this message | ||
max wrote a fix for satch666's function, but it too has a little bug... If you write IP
09.111.111.1, it will return TRUE.
<?
$num="(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])";
/*
\\d => numbers 0-9
[1-9]\\d => numbers 10-99 --> Here was the bug in max's code
1\\d\\d => numbers 100-199
2[0-4]\\d => numbers 200-249
25[0-5] => numbers 250-255
*/
if (!preg_match("/^$num\\.$num\\.$num\\.$num$/", $$ip_addr)) echo "Wrong IP
Address\\n";
?>
P.S. Why did you write [0-9] and not \\d?
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52836
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52836&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52836&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52836&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52836&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52836&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52836&report=yes
Search -- http://master.php.net/manage/user-notes.php