How to Check a string contains a specific word in PHP (with Multiple Answers)

PHP have many functions to find the occurrence of word.


$x = 'Where are you?';

if (strpos($x, 'are') !== false) { echo 'specific Word exists'; }


if (mb_strpos($x, 'are') !== false) { echo 'specific Word exists'; }


$stringresult = stripos($x, 'are');

if ($stringresult === false) { echo 'specific Word does not exist';
} else { echo 'specific Word exists'; }

Count Number of Times a Word Found.


$oritext = 'This is a Book';
echo substr_count($oritext, 'is'); // return 2

if (substr_count($oritext, 'is') > 0) { echo "is exists"; }


You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *