PHP strrchr() Function

Definition

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

Syntax

PHP strrchr() Function has the following syntax.

strrchr(string,char)

Parameter

ParameterIs RequiredDescription
stringRequired.String to search
charRequired.String to find. If this is a number, it will search for the character matching the ASCII value of that number

Return

PHP strrchr() Function returns all characters from the last occurence of a string, to the end of the main string, or FALSE if the character is not found.

Example

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


<?php
echo strrchr("Hello world from java2s.com!","world");
?>

The code above generates the following result.

Example 2

Search a string for the ASCII value of "o" and return all characters from this position to the end of the string:


<?php
echo strrchr("Hello world from java2s.com!",111);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions