Home >>PHP String Functions >PHP strrpos() Function
PHP strrpos() function is used to find the position of the last occurrence of a specified string inside another string. This function is case-sensitive. It returns an integer value which is the position of the last occurrence of the specified string. The case-insensitive version of this function in strripos() function.
Syntax:
strrpos($string, $find, $start);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter defines the string to be searched. |
find | This is a required parameter. This parameter defines the string to find. |
start | This is an optional parameter. This parameter defines where to begin the search. |
Here is an example of strrpos() function in PHP:
<html> <body> <?php echo strrpos("PHP is a server side scripting language. PHP stands for Hypertext Pre-processor.","PHP"); ?> </body> </html>
Here is an another example of strrpos() function in PHP:
<html> <body> <?php $string = "PHP, Java, Python, JavaScript, PHP Framework, PHPTPOINT"; $position = strrpos($string, "PHP", 5); if ($position == true){ echo "Found at position " . $position; } else{ echo "Not Found"; } echo "<br> <br>"; $position = strrpos($string, "php", 5); // Not found due to case-sensitive if ($position == true){ echo "Found at position " . $position; } else{ echo "Not Found"; } ?> </body> </html>