PHP strrchr() Function
In this chapter you will learn:
- Definition for PHP strrchr() Function
- Syntax for PHP strrchr() Function
- Parameter for PHP strrchr() Function
- Return for PHP strrchr() Function
- Example - Search a string for "world", and return all characters from this position to the end of the string
- Example - Search a string for the ASCII value
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
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to search |
char | Required. | 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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP strrev() Function
- Syntax for PHP strrev() Function
- Parameter for PHP strrev() Function
- Return for PHP strrev() Function
- Example - Reverse a string
Home » PHP Tutorial » PHP String Functions