Home >Backend Development >PHP Tutorial >PHP finds the last occurrence of a string in another string (case sensitive) function strrpos()

PHP finds the last occurrence of a string in another string (case sensitive) function strrpos()

黄舟
黄舟Original
2017-11-06 09:19:281607browse

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

Since PHP 5.0, the find parameter can be a string of more than one character.
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 :
In PHP 5.0, the start parameter is added.
Example:

<?php 
echo strrpos("Hi Friend!","Fr");//strpos函数是否可以认为是字符在字符所在字符串的位置查询;
 ?>

Output result: 3

Example

<?php
echo strrpos("Hello world!","wo");
?>

Output:

6

Use strrpos to verify whether the link is a link of http protocol

<?php
$url="http://www.baidu.com";
if (strrpos($url, &#39;http://&#39;) !== 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn