Affects: PHP4, PHP5
PHP is by far one of the most popular server side programming languages available today (55% market share in our poll) however it has its own fair share of quirks.
For reasons unknown to us, PHP decided that the return value from the strpos() function will return an integer index... or maybe a boolean FALSE!
Huh say what?!
Almost every programming language has a method or two to find the position of a substring in a string.
var idx = 'Hello World'.indexOf('Wo');
alert('Found: "Wo" at index ' + idx);
They all return a positive index if the substring is found, or -1 if not.
Unfortunately PHP can sometimes return FALSE, or 0 (zero), or "" when it doesn't find the substring, which makes programming logic to handle this extremely difficult.
Known Workarounds: Several. Many developers have written new extensions to the String Class, standalone functions and more. Rather than claim to have the best solution ourselves, please send in your workaround using the comments below and we'll try to pick and highlight the best solutions from the submissions.
Example Workaround Code:
Related Issues: None.
Submit a bug