Backend Development 3 min read

PHP strrpos() Function – Find the Last Occurrence of a Substring

This article explains PHP's strrpos() function, detailing its purpose, parameters, return values, and provides two practical code examples demonstrating how to locate the last occurrence of a substring with optional offsets in a string.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP strrpos() Function – Find the Last Occurrence of a Substring

strrpos() calculates the position of the last occurrence of a needle string in a haystack string.

Explanation: Returns the numeric position of the needle in the haystack. In PHP 4 the needle must be a single character; if a string is given only its first character is used.

Parameters

haystack – The string to search in.

needle – The string to search for; if not a string it is converted to an integer character code.

offset – Optional offset; negative values start counting from the end of the string.

Return value

Returns the position of needle if found, or FALSE otherwise.

Example 1

Example 2

backendProgrammingphpstring-functionsstrrpos
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

login 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.