|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kkitts at clearviewcatv dot net
New email:
PHP Version: OS:


 [2007-11-08 17:21 UTC] kkitts at clearviewcatv dot net
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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-08 18:03 UTC]
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 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-2023 The PHP Group
All rights reserved.
Last updated: Mon Jun 05 00:03:38 2023 UTC