Link Search Menu Expand Document

PHP stripos Examples

Important: Use Correct Comparsion Operator!Only ever compare with the identical operators "===" , "!==" and only ever compare with false

Postive match

if (stripos($str, $substr) !== false) {
     echo("Does match!")

Negative match

if (stripos($str, $substr) === false) {
     echo("Does not match.")
Check out for more details

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 (stripos($str, $substr, 5) === false) {
By using the return value of strpos() you can do repeated searches:
$pos1 = stripos($str, $substr);
$pos2 = stripos($str, $substr, $pos1 + strlen($pos1));

Search Backwards

For backwards searching there is another special method strripos() with the same signature:
if (strripos($str, $substr) === false) {
     echo("Does not match.")