It can be possible in three ways.
Firstly by using regex
with preg_match_all()
$str = "php is fun, linux is interesting, Windows is fun, Ubuntu is ubuntu, Perl is fun,";
$res = preg_match_all("/(linux is interesting|Windows is fun|Ubuntu is ubuntu)/", $str);
if ($res)
echo "Text is founded in string";
If you just need to know if any of the words is present, use preg_match as above. If you need to match all the occurences of any of the words, use preg_match_all and |
pipe sign indicates or
secondly by using the stripos()
which indicates if a string contains specific words or not and if contains it returns the starting position of the words.
print_r(stripos($str, "Windows is fun"))
Thridly if you are separating your string sentences with ,
delimiter then it can be possible by using explode()
to convert string into array then match one by one with another array.
$str = "php is fun, linux is interesting, Windows is fun, Ubuntu is ubuntu, Perl is fun,";
$exp = explode(",", $str);
$match = array("linux is interesting", "Windows is fun", "Ubuntu is ubuntu");
foreach ($exp as $key => $value) {
foreach ($match as $key_match => $value_match) {
if ($value === $value_match) {
echo "String match founded <br>";
}
}
}