There are many ways to do this, from using multiple strpos
to comparisons after a str_replace
. Here we can split the string into an array and calculate the intersection with another array:
$mystring = 'my food is okay. its delicious';
$findme = ['m', 'e', 's'];
Check for ANY of the characters in the array:
if(array_intersect($findme, str_split($mystring))) {
echo "1 or more found";
}
Check for ALL of the characters in the array:
if(array_intersect($findme, str_split($mystring)) == $findme) {
echo "all found";
}
And for fun, run the array through a callback and filter it based upon whether it is in the string. This will check for ANY:
if(array_filter($findme, function($v) use($mystring) {
return strpos($mystring, $v) !== false;
}))
{
echo "1 or more found";
}
This will check for ALL:
if(array_filter($findme, function($v) use($mystring) {
return strpos($mystring, $v) !== false;
}) == $findme)
{
echo "all found";
}