如何查看给定字符串是否包含我想要查找的多个字符?例如:
$manywords = "apple orange pineapple banana cat";
if (!(strstr($manywords, 'apple'||'cat')))
{
echo "either word found";
}
有没有办法可以使用strstr
函数,而不必按如下方式编写两次:
if (!((strstr($manywords, 'apple')||(strstr($manywords, 'cat')))
{
echo "either word found";
}
答案 0 :(得分:3)
$did_it_match = preg_match('/apple|cat/',$manywords);