(PHP 4, PHP 5, PHP 7)
strrchr — Find the last occurrence of a character in a string
$haystack
, string $needle
) : string|false
This function returns the portion of haystack
which
starts at the last occurrence of needle
and goes
until the end of haystack
.
haystack
The string to search in
needle
If needle
contains more than one character,
only the first is used. This behavior is different from that of
strstr().
Dacă needle
nu este un șir de caractere, el este
transformat în întreg și aplicat ca valoarea ordinală a caracterului.
Acest comportament este învechit începând cu PHP 7.3.0 și utilizarea lui este
foarte nerecomandată. În dependență de comportamentul dorit
needle
trebuie transformat în mod explicit în șir de
caractere, sau trebuie efectuat un apel explicit către chr().
This function returns the portion of string, or false
if
needle
is not found.
Versiune | Descriere |
---|---|
8.0.0 |
Passing an int as needle is no longer supported.
|
7.3.0 |
Passing an int as needle has been deprecated.
|
Example #1 strrchr() example
<?php
// get last directory in $PATH
$dir = substr(strrchr($PATH, ":"), 1);
// get everything after last newline
$text = "Line 1\nLine 2\nLine 3";
$last = substr(strrchr($text, 10), 1 );
?>
Notă: Această funcție acceptă și date binare.