php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43218 possible stripos bug...
Submitted: 2007-11-08 17:21 UTC Modified: 2007-11-08 18:03 UTC
From: kkitts at clearviewcatv dot net Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.4 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2007-11-08 17:21 UTC] kkitts at clearviewcatv dot net
Description:
------------
This may or may not be a bug, but it is very inconvenient.

stripos returns the location of string1 within string2.  If it doesn't find string1 within string2, it returns false.

This works well, unless string1 is found at position 0 (the first character of the string).  In this case, it returns the position of string1 in string2, which happens to be 0.  This is also the value of the "FALSE" definition.

So, when I have code like below, the echo statement never gets executed because the if() function thinks 0 == FALSE.  I'm still trying to think of a manual workaround.

Possible fix:  rewrite stripos to have optional 4th parameter specifying an alternate return value if string1 isn't found in string2 (such as stripos($str, "pineapple", 0, -1), which would return -1 instead of FALSE).

Reproduce code:
---------------
$str = "pineapple";

if(strripos($str, "pineapple", 0))
{
    echo "Comments cannot contain \"pineapple\".<br/>";
}



Expected result:
----------------
Comments cannot contain "pineapple".

Actual result:
--------------
(nothing)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-08 18:03 UTC] scottmac@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

if(strripos($str, "pineapple", 0) !== false)

You can do type comparison to check this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 05:01:28 2024 UTC