From: phraje at gmail dot com Operating system: linux 2.6.18 & win32 PHP version: 5.2.1 PHP Bug Type: Unknown/Other Function Bug description: strstr() and stristr() cannot find zero
Description: ------------ If a haystack string has a zero (0) as its last character, and the needle is zero, neither strstr() or stristr() will match it. Can be worked around by concatenating a trailing space to the haystack string. Reproduce code: --------------- $haystack="this is a string that ends in 0"; $needle=sprintf("%d",0); if(strstr($haystack,$needle)) { printf("%s.\n",$haystack); } if(stristr($haystack,$needle)) { printf("%s.\n",$haystack); } $haystack="this is a string that doesn't end in 0 "; if(strstr($haystack,$needle)) { printf("%s.\n",$haystack); } if(stristr($haystack,$needle)) { printf("%s.\n",$haystack); } $haystack="this is a string that ends in 1"; $needle=sprintf("%d",1); if(strstr($haystack,$needle)) { printf("%s.\n",$haystack); } if(stristr($haystack,$needle)) { printf("%s.\n",$haystack); } Expected result: ---------------- this is a string that ends in 0. this is a string that ends in 0. this is a string that doesn't end in 0 . this is a string that doesn't end in 0 . this is a string that ends in 1. this is a string that ends in 1. Actual result: -------------- this is a string that doesn't end in 0 . this is a string that doesn't end in 0 . this is a string that ends in 1. this is a string that ends in 1. -- Edit bug report at http://bugs.php.net/?id=41013&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41013&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41013&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41013&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41013&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41013&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41013&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41013&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41013&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41013&r=support Expected behavior: http://bugs.php.net/fix.php?id=41013&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41013&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41013&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41013&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41013&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41013&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41013&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41013&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41013&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41013&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41013&r=mysqlcfg