strchr()
strchr() — Alias of strstr().
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
strchr() is an alias of strstr(): same parameters, same return value.
Signature
strchr(string $haystack, string $needle, bool $before_needle = false): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $haystack | string | The input string. |
| $needle | string | The string to search for. |
| $before_needle | bool | If true, strstr() returns the part of the haystack before the first occurrence of the needle (excluding the needle). |
Return value
Returns the portion of string, or false if needle is not found.
Example
A runnable snippet:
$email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain, PHP_EOL; // prints @example.com $user = strstr($email, '@', true); echo $user, PHP_EOL; // prints name
All PHP 8.5 built-in functions
Reference card built from the PHP manual page strchr() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.