How can PHP's strrpos() function be used to search for a string backwards from a specified offset?

To search for a string backwards from a specified offset using PHP's strrpos() function, you can provide an additional parameter specifying the offset from where the search should start. This allows you to search for the string starting from the end of the string and moving towards the beginning. The strrpos() function returns the position of the last occurrence of the string within the given string.

$string = "hello world";
$search = "o";
$offset = 5;

$position = strrpos($string, $search, -$offset);

if ($position !== false) {
    echo "Found '$search' at position $position starting from offset $offset";
} else {
    echo "String '$search' not found starting from offset $offset";
}