English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP strrchr() Function Usage and Example

PHP String Function Manual

The strrchr() function is used to find the last occurrence of a specified character in a string.

Syntax

strrchr(string, char)

Definition and Usage

It is used to find the last occurrence of a character in a string.

Return Value

Returns the remaining part of the string (from the matching position). If the searched string is not found, it returns FALSE.

Parameter

Serial NumberParameters and Description
1

string

It specifies the string to be searched

2

char

It specifies the string to be searched. If the parameter is a number, it searches for the character corresponding to the ASCII value of that number.

Online Example

Try the following example, which returns the substring before the first occurrence of "PHP":

<?php
    //Returns the substring before the first occurrence of "PHP"
   echo strrchr("Hello PHP, very good!", "PHP"); 
?>
Test and see‹/›

Output Result

P, very good!

PHP String Function Manual