strrchr

(PHP 4, PHP 5, PHP 7)

strrchrFind the last occurrence of a character in a string

Descrierea

strrchr ( 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.

Parametri

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().

Valorile întoarse

This function returns the portion of string, or false if needle is not found.

Istoricul schimbărilor

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.

Exemple

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($text10), );
?>

Note

Notă: Această funcție acceptă și date binare.

A se vedea și

  • strstr() - Find the first occurrence of a string
  • strrpos() - Find the position of the last occurrence of a substring in a string