PHP 8 Guide: How to find a specific value in a String?

Problem:
I want to find a certain word in one of my Strings. How can I do that in PHP 8?

Answer:
You can use the function str_contains(‘MyString’, ‘TheWordILookFor’) to find a certain word in your String.

Example:
$myString = ‘I want to find the word Kindergarten’;
if(str_contains(‘myString’, ‘Kindergarten’)) {
echo ‘true’;
}


More about PHP


PHP.net


back