The str_contains() function in PHP 8.4 and PHP 8.5 works exactly the same as it did when introduced in PHP 8.0. It performs a case-sensitive check to see if one string (the "needle") exists inside another string (the "haystack").
Syntax.
The function signature is straightforward:
str_contains(string $haystack, string $needle): bool
It returns true if the needle is found, and false otherwise.
Basic Example:
<?php
$text = "Hello, welcome to PHP programming!";
if (str_contains($text, PHP )) {
echo "The text contains PHP .";
} else {
echo "The text does not contain PHP .";
}
// Output: The text contains PHP .?>
This example is adapted from a common PHP tutorial demonstrating the function.