What is the role of string function strrpos()?
strrpos() function finds the last occurrence of a string within another string. This function is case-sensitive, contrary to the strripos() function, which is not case-sensitive. This article will guide you to understand the php strrpos() function.
strrpos() function syntax
strrpos(string,find,start)
This function has three parameters, the first two parameters are required, and the third parameter is optional Optional
Parameter | Description |
---|---|
string | Required. Specifies the string to be searched for. |
find | Required. Specifies the characters to search for. |
start | Optional. Specifies the location from which to start the search. |
The return value of strrpos() function
strrpos() functionreturns a string The last occurrence of another string, or FALSE if the string is not found. The string position starts from 0, not from 1.
The related functions are:
stripos() - Find the first occurrence of a string in another string position (case-insensitive)
strpos() - Find the position of the first occurrence of a string in another string (case-sensitive)
strripos() - Find the last occurrence of a string in another string (case-insensitive)
strrpos() function example
The following example uses the strrpos() function to find the last occurrence of "php" in the string. The code is as follows
<?php echo strrpos("You love php, I love php too!","php"); ?>
The code runs the browser output result:
[Related article recommendations]
php string function stripos Definition and usage of ()
php strpos() function example detailed explanation
php string function strripos() detailed example
The above is the detailed content of Detailed explanation of string function strrpos(). For more information, please follow other related articles on the PHP Chinese website!