Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

PHP: Check if a string contains a specific word.

You can use PHP’s built-in function called str_contains to check if the given word exists in a string or not. If it finds the word it will return true otherwise it will return false. This function is case-sensitive.

PHP 8: str_contains function

$word = "fox";
$mystring = "The quick brown fox jumps over the lazy dog";
// Test if string contains the word 
if(str_contains($mystring, $word)){
    echo "Word Found!";
} else{
    echo "Word Not Found!";

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments