Link Search Menu Expand Document

PHP strrpos Examples

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

Postive match

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

Negative match

if (strrpos($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 end use an offset as third parameter:
if (strrpos($str, $substr, 5) === false) {
By using the return value of strrpos() you can do repeated searches:
$pos1 = strrpos($str, $substr);
$pos2 = strrpos($str, $substr, $pos1 + strlen($pos1));