ID:               41013
 Updated by:       [EMAIL PROTECTED]
 Reported By:      phraje at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Unknown/Other Function
 Operating System: linux 2.6.18 & win32
 PHP Version:      5.2.1
 New Comment:

.


Previous Comments:
------------------------------------------------------------------------

[2007-04-07 00:51:11] webmaster at wiedmann-online dot de

In the first two cases strtr() or stristr() returns the string "0".
A loose boolean comparisons with "0" is FALSE and so the if statement
is not executed.

In your case you can change the code to:
if(false !== strstr($haystack,$needle)) { printf("%s.\n",$haystack); }

BTW: better use strpos() in this case.

------------------------------------------------------------------------

[2007-04-06 19:04:25] phraje at gmail dot com

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 this bug report at http://bugs.php.net/?id=41013&edit=1

Reply via email to