Categories: PHP

strrchr() – PHP String Functions

Syntax :

string strrchr ( string, char_string );

Description :

strrchr() function will find the last occurrence of char_string in a string and returns all characters from this position to the end of the string.

Note : case sensitive and binary-safe function.

Parameter :

  • string – This is a Required parameter. This is the string in which search will take place.
  • char_string – This is a Required parameter. It contains the value to be searched. If we pass this parameter as a number, then it will search for the character matching the ASCII value of the number.  This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the char_string should either be explicitly cast to string, or an explicit call to chr() should be performed.

Output :

It will returns below values:

  • the portion of string after the last occurrence is found in the string.
  • FALSE if the search is not found in the string.

ChangeLog :

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, Description
PHP 4.3.0 , It is binary safe from this version.
[/table]


Related articles : strstr(), strrpos().


strrchr() – PHP Functions Example 1 : It returns the string from the last occurrence of search is found.
<?php
echo strrchr("Hi from tutorialmines.","t"); // case-sensitive comparison
?>

Output of above code in the browser is as below:

torialmines.

strrchr() – PHP Functions Example 2 : It will find the last occurrence of character “t”, its ASCII value is 116.
<?php
echo strrchr("Hi from tutorialmines.",116);// ASCII value of t is 116.
?>

Output of above code in the browser is as below:

torialmines.

strrchr() – PHP Functions Example 3 : It will return FALSE, if string is not found in the search.
<?php
echo "returns false, if search string is not found.\n";
var_dump(strrchr("Hi from tutorialmines.","k"));// returns false, if search string is not found.
echo "<br/>";
var_dump(strrchr("Hi from tutorialmines.","ME")); // case-sensitive comparison
echo "<br/>";
var_dump(strrchr("Hi from tutorialmines.",'098'));// ASCII value of bt is 098.
?>

Output of above code in the browser is as below:

returns false, if search string is not found.
bool(false)
bool(false)
bool(false)

jyoti rani

Recent Posts

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

2 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

2 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

2 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

2 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

2 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

2 months ago