ID: 51148
Comment by: alessandro dot romani at vivanet dot it
Reported By: fabriziodimeo at alice dot it
Status: Open
Bug Type: *Regular Expressions
Operating System: windows and linux
PHP Version: 5.3.1
New Comment:
I tested the two functions (preg_match and ereg) and this is the
result:
<?php
function test($str)
{
if (preg_match("/[a-zA-Z0-9]+/",$str))
{
echo "it's ok<BR>";
}
else
{
echo "not ok<BR>";
}
}
function test2($str)
{
if (ereg("^[a-zA-Z0-9]+$",$str))
{
echo "it's ok<BR>";
}
else
{
echo "not ok<BR>";
}
}
echo "PREG_MATCH<BR><BR>";
test("iao");
test("$iao");
test("iao!");
test("123!");
test("123");
echo "<BR>";
echo "EREG<BR><BR>";
test2("iao");
test2("$iao");
test2("iao!");
test2("123!");
test2("123");
?>
The result is:
PREG_MATCH
not ok
not ok
not ok
not ok
not ok
EREG
it's ok
not ok
not ok
not ok
it's ok
Previous Comments:
------------------------------------------------------------------------
[2010-02-25 18:56:50] fabriziodimeo at alice dot it
Description:
------------
preg_match do not match correctly.
Reproduce code:
---------------
<?php
function anti_injection($stringa) {
$pattern="/[A-Za-z0-9]/";
if (preg_match($pattern, $stringa)) {
echo "ok"; }
else {
echo "hacking";
}
}
$str="c";
anti_injection($str);
$str="ciao!";
anti_injection($str);
?>
Expected result:
----------------
ok
hacking
Actual result:
--------------
ok
ok
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=51148&edit=1