Important: use the correct comparsion operator!With strpos() functions always use the identical operator "===" or "!==" and compare to "false"
CORRECT
if (strpos($str, $substr) === false) {
if (strpos($str, $substr) !== false) {
WRONG
if (strpos($str, $substr) != false) {
if (strpos($str, $substr) == false) {
The reason for using the identical operators (that also check for the type of the value) "===" or "!==" is that strpos() might return "0" for match at the beginning or "false" for no match which cannot be distinguished by "==" or "!=".
Case Sensitivity
Simply use stripos() instead of strpos()
strpos()
case sensitive searching
stripos()
case insensitive searching
Search From Offset
If you want to continue a search or want to skip something at the start use an offset as third parameter:
if (strpos($str, $substr, 5) === false) {
By using the return value of strpos() you can do repeated searches: