Home >Backend Development >PHP Tutorial >PHP finds the last occurrence of a string in another string (case sensitive) function strrpos()
Example
Find the last occurrence of "php" in the string:
<?php echo strrpos("I love php, I love php too!","php"); ?>
Definition and usage
strrpos() function Finds the last occurrence of a string within another string (case sensitive).
Note: The strrpos() function is case-sensitive.
Related functions:
strpos() - Find the first occurrence of a string in another string (case sensitive)
stripos() - Find the first occurrence of a string in another string (case insensitive)
strripos() - Find the last occurrence of a string in another string (case-insensitive)
Syntax
strrpos(string,find,start)
Parameters | 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. |
Technical details
Return value: | Returns a string within another string The position of the last occurrence, or FALSE if the string is not found. Note: The string position starts from 0, not from 1. |
PHP Version: | 4+ |
##Update Log : | Since PHP 5.0, the find parameter can be a string of more than one character.
In PHP 5.0, the start parameter is added. |
<?php echo strrpos("Hi Friend!","Fr");//strpos函数是否可以认为是字符在字符所在字符串的位置查询; ?>Output result: 3Example
<?php echo strrpos("Hello world!","wo"); ?>Output:
6
<?php $url="http://www.baidu.com"; if (strrpos($url, 'http://') !== 0) echo "链接为http协议的链接"; ?>
The above is the detailed content of PHP finds the last occurrence of a string in another string (case sensitive) function strrpos(). For more information, please follow other related articles on the PHP Chinese website!