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

黄舟
Release: 2023-03-17 06:54:01
Original
1581 people have browsed it

Example

Find the last occurrence of "php" in the string:

<?php
echo strrpos("I love php, I love php too!","php");
?>
Copy after login

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)
Copy after login
ParametersDescription
stringRequired. Specifies the string to be searched for.
findRequired. Specifies the characters to search for.
startOptional. 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函数是否可以认为是字符在字符所在字符串的位置查询;
 ?>
Copy after login

Output result: 3

Example

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

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协议的链接";
?>
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!