How to use php strrchr function?

藏色散人
Release: 2023-02-22 22:50:01
Original
3056 people have browsed it

php The strrchr function is used to find the last occurrence of a string in another string and return all characters from that position to the end of the string. Its syntax is strrchr(string,char).

How to use php strrchr function?

php How to use strrchr function?

Definition and Usage

strrchr() function finds the last occurrence of a string in another string and returns the character from that position to All characters at the end of the string.

Note: This function is binary safe.

Syntax

strrchr(string,char)
Copy after login

Parameters

string Required. Specifies the string to search for.

char required. Specifies the characters to search for. If the argument is a number, searches for characters matching the ASCII value of this number.

Return value:

Returns all characters from the last occurrence of a string in another string to the end of the main string.

If this character is not found, returns FALSE.

PHP Version: 4

Change Log: In PHP 4.3, this function became binary safe.

Example 1

Search for the position of "What" in the string and return all characters from that position to the end of the string:

<?php
echo strrchr("Hello world! What a beautiful day!",What);
?>
Copy after login

Output:

What a beautiful day!
Copy after login

Example 2

Search for the position of "o" in the string using the ASCII value of "o" and return the position from that position to the string All characters ending with:

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

Output:

ello world!
Copy after login

Example 3

Search for the position of "Shanghai" in the string and return the position from that All characters up to the end of the string:

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

Output:

Shanghai!
Copy after login

The above is the detailed content of How to use php strrchr function?. 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