HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

strrchr

Description

The strrchr of String for PHP find the last occurrence of a character in a string.

Syntax

strrchr(
    string $haystack,
    string $needle,
    bool $before_needle = false
): string|false

Parameters

haystack

The string to search in

needle

The string to search for.

If needle contains more than one character, only the first is used. This behavior is different from that of strstr().

before_needle

If true, strrchr() returns the part of the haystack before the last occurrence of the needle (excluding the needle).

Return

Returns the portion of string, or false if needle is not found.

Examples

1 · haystack needle

<?

$haystack = 'CASEcase';
$needle = 'string';

$return = strrchr($haystack, $needle);

echo $return;
se

2 · before_needle

<?

$haystack = 'CASEcase';
$needle = 'string';
$before_needle = true;

$return = strrchr($haystack, $needle, $before_needle);

echo $return;
CASEca