|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-11-08 18:03 UTC] scottmac@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 13:00:01 2025 UTC |
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)