str_contains()
str_contains() — Determine if a string contains a given substring.
Built-in function of PHP 8.5. The manual lists it as available in PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Performs a case-sensitive check indicating if needle is contained in haystack.
Signature
str_contains(string $haystack, string $needle): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $haystack | string | The string to search in. |
| $needle | string | The substring to search for in the haystack. |
Return value
Returns true if needle is in haystack, false otherwise.
Example
A runnable snippet:
if (str_contains('abc', '')) { echo "Checking the existence of the empty string will always return true"; }
Output:
Checking the existence of the empty string will always return true
See also
str_ends_with(), str_starts_with(), stripos(), strrpos(), strripos(), strstr(), strpbrk(), substr(), preg_match()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page str_contains() (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.