#30158 [Opn->Bgs]: strpos doesn't work as it should
| From: | rasmus@php.net | Date: | Sun, 19 Sep 2004 22:19:07 +0000 |
| Subject: | #30158 [Opn->Bgs]: strpos doesn't work as it should | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-66426@lists.php.net to get a copy of this message | ||
ID: 30158
Updated by: rasmus@php.net
Reported By: a dot bendilas at zefxis dot gr
-Status: Open
+Status: Bogus
Bug Type: Strings related
Operating System: WinXP SP2
PHP Version: 4.3.8
New Comment:
Why are you doing a === to true? strpos is clearly documented to
return a integer specifying the position in the string on a match or
false on a failure. It will never return true.
Previous Comments:
------------------------------------------------------------------------
[2004-09-19 22:09:19] a dot bendilas at zefxis dot gr
Description:
------------
Although strpos returns the position of the needle correctly, when
testing the return value with a boolean operator to see if it's true,
it produces the opposite result.
Reproduce code:
---------------
$string = 'Once upon a time in America';
$srchstring = 'time';
$position = strpos($string, $srchstring);
echo 'String: '.$string.'<br />';
echo 'Search string: '.$srchstring.'<br />';
echo 'Position of search string: '.$position.'<br />';
if ((strpos($string, $srchstring) === true)) echo 'Search string is
included in the original string!'; else echo 'Search string is not
included in the original string!';
Expected result:
----------------
Search string is included in the original string!
Actual result:
--------------
Search string is not included in the original string!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30158&edit=1