strrchr

Find the last occurrence of a character in a string

&reftitle.description; ``string``false```strrchr` `string` `haystack` `string` `needle` `bool` `before_needle`&false;

This function returns the portion of `haystack` which starts at the last occurrence of `needle` and goes until the end of `haystack`.

&reftitle.parameters;

`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`.

  &strings.parameter.needle.non-string;

`before_needle`

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

&reftitle.returnvalues;

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

&reftitle.changelog;

&Version; | &Description;
8.3.0 | The `before_needle` parameter was added.
&strings.changelog.needle-empty;
8.0.0 | Passing an &integer; as `needle` is no longer supported.
7.3.0 | Passing an &integer; as `needle` has been deprecated.

&reftitle.examples;

### `strrchr` example

    <?php
    $ext = strrchr('somefile.txt', '.');
    echo "file extension: $ext \n";
    $ext = $ext ? strtolower(substr($ext, 1)) : '';
    echo "file extension: $ext";
    ?>

&example.outputs.similar;

    file extension: .txt
    file extension: txt

&reftitle.notes; ¬e.bin-safe;
&reftitle.seealso;

- `strstr`
- `strrpos`