strstr

Find the first occurrence of a string

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

Returns part of `haystack` string starting from and including the first occurrence of `needle` to the end of `haystack`.

This function is case-sensitive. For case-insensitive searches, use `stristr`.

If it is only required to determine if a particular `needle` occurs within `haystack`, the faster and less memory intensive `str_contains` function should be used instead.

&reftitle.parameters;

`haystack`

- The input string.

`needle`

- The string to search for.

  &strings.parameter.needle.non-string;

`before_needle`

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

&reftitle.returnvalues;

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

&reftitle.changelog;

&Version; | &Description;
&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;

### `strstr` example

    <?php
    $email  = 'name@example.com';
    $domain = strstr($email, '@');
    echo $domain; // prints @example.com

    $user = strstr($email, '@', true);
    echo $user; // prints name
    ?>

&reftitle.seealso;

- `stristr`
- `strrchr`
- `strpos`
- `strpbrk`
- `preg_match`