strrchr() – PHP String Functions
Syntax :
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.
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:
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:
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:
bool(false)
bool(false)
bool(false)