strrchr() Function in PHP With Example

Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.

Hello Friends Today, through this tutorial, I will tell you How to Use `strrchr()` function using PHP, PHP 8, PHP 8.1, PHP 8.2 With Example. In PHP, the `strrchr()` function is used to find the last occurrence of a character in a string and return the portion of the string starting from that character until the end of the string. The function syntax is as follows:

<?php
strrchr(string $haystack, string $needle): string|false
?>

1. `$haystack`: The string to search in.
2. `$needle`: The character or substring to search for.

Here’s an example demonstrating the usage of `strrchr()` function in PHP 8.2:

<?php
$string = "Hello, world! This is a test string.";
$character = 'o';
$last_occurrence = strrchr($string, $character);
if ($last_occurrence !== false) {
echo "Last occurrence of '$character' found: $last_occurrence";
} else {
echo "Character '$character' not found in the string.";
}
?>

In this example:
1. The `$string` variable contains the input string.
2. We are searching for the last occurrence of the character `’o’`.
3. The `strrchr()` function returns the substring starting from the last occurrence of `’o’` till the end of the string.
4. If the character is found, it will output the substring starting from the last occurrence of `’o’`. Otherwise, it will indicate that the character was not found in the string.

Remember, `strrchr()` is case-sensitive. If you want a case-insensitive search, you should use `strripos()` or `mb_strripos()` functions.

Cialis (Tadalafil) är den främsta konkurrenten till Viagra (Sildenafil) på marknaden för erektil dysfunktion. köpa Cialis i Sverige föredras av många på grund av sin längre varaktighet och anses vara det mest kostnadseffektiva varumärkesbaserade ED-läkemedlet som finns tillgängligt i Sverige. Cialis finns i två varianter: Cialis och Cialis Daily, och fyra olika doseringar: 2,5 mg, 5 mg, 10 mg och 20 mg, erbjuder Cialis också en rad olika alternativ för att passa patientens behov.