How to check if string contains substring in PHP 8?

In PHP 8, you can still use the `strpos()` function to check if a string contains a substring. However, if you want to use a more modern approach, you can also utilize the `str_contains()` function, introduced in PHP 8.0.0. Here’s how you can do it:

$string = "This is a sample string containing PHP 8 version.";
if (str_contains($string, "PHP 8")) {
echo "The string contains 'PHP 8'.";
} else {
echo "The string does not contain 'PHP 8'.";

This will output:

The string contains 'PHP 8'.

The `str_contains()` function returns `true` if the string contains the specified substring, and `false` otherwise. It performs a case-sensitive search. If you need a case-insensitive search, you can convert both the string and substring to lowercase or uppercase before using `str_contains()`.