|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-10-03 01:49 UTC] daijoubu at videotron dot ca
Description:
------------
string strstr ( string haystack, string needle)
If needle is numeric and lenght of 1 at the end of the haystack, returns false
No problem if needle is 'a' ($test = '123456789a') or '90' ($test = '1234567890')
Reproduce code:
---------------
$test = '1234567890';
if (strstr($test, '0'))
{
$result = 1;
}
Expected result:
----------------
result = 1;
Should output the same as:
if (strpos($test, '0') !== false)
{
$result = 1;
}
Actual result:
--------------
$result = 0;
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 13 13:00:01 2025 UTC |
from the manual page for strstr(): "Returns part of haystack string from the first occurrence of needle to the end of haystack." strstr() works just fine, the last char in your string is '0' (zero). Try this: <?php $test = '1234567890'; var_dump(strstr($test, '0')); ?> # php test.php string(1) "0" You see it's string, it's not boolean. To get reliable results, always check the type of returned variable. Like this: <?php $test = '1234567890'; if (strstr($test, '0') !== false) { $result = 1; } ?>