PHP strripos() Function: Case‑Insensitive Search for the Last Occurrence

This article explains PHP’s strripos() function, which performs a case‑insensitive search for the last occurrence of a substring, details its parameters and return values, and provides a complete example with code and expected output.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP strripos() Function: Case‑Insensitive Search for the Last Occurrence

The PHP strripos() function searches for the last occurrence of a needle string within a haystack string without regard to case, returning the zero‑based position or FALSE if the needle is not found.

Parameters haystack – the string to be searched. needle – the string or character to locate. offset (optional) – an integer offset; a negative value starts the search from the beginning up to that offset.

Return value

Integer position of the needle in the haystack (starting at 0) or FALSE when the needle does not occur.

Example

<?php
$haystack = 'ababcd';
$needle = 'aB';
$pos = strripos($haystack, $needle);
if ($pos === false) {
    echo "Sorry, we did not find ($needle) in ($haystack)";
} else {
    echo "Congratulations!
";
    echo "We found the last ($needle) in ($haystack) at position ($pos)";
}
?>

Output

//Congratulations!
//We found the last (aB) in (ababcd) at position (2)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendTutorialcase-insensitivestring-functions
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.