php,如果一个字符串包含两个不同的字符



如何查看给定字符串是否包含我要查找的多个字符?例如:

$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";
}
$did_it_match = preg_match('/apple|cat/',$manywords);

相关内容

最新更新