PHP strrchr()Functions

PHP String 参考手册PHP String Reference Manual

Examples

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

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

Run Example »

Definition and Usage

The strrchr() function finds the last occurrence of a string within another string, and returns all characters from that position to the end of the string.

Note:This function is binary-safe.


Syntax

strrchr(string,char)

Parameter Description
string Required. Specifies the string to be searched.
char Required. Specifies the character to search for. If this parameter is a number, it searches for the character matching the ASCII value of the number.

Technical Details

Return Value: Returns all characters from the last occurrence of a string within another string to the end of the main string. Returns FALSE if the character is not found.
PHP Version: 4+
Changelog: In PHP 4.3, this function became binary-safe.


More Examples

Example 1

Search for the position of "" 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);
?>

Run Example »

Example 2

Search for the position of "o" in the string using the ASCII value of "o", and return all characters from that position to the end of the string:

<?php
echo strrchr("Hello world!",111);
?>

Run Example »


PHP String 参考手册PHP String Reference Manual Other Extensions