Home >Backend Development >PHP Problem >How to use php strrchr function?

How to use php strrchr function?

藏色散人
藏色散人Original
2019-05-30 13:21:533102browse

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)

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);
?>

Output:

What a beautiful day!

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);
?>

Output:

ello world!

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");
?>

Output:

Shanghai!

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!

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