嗨我必须在一个字符串中搜索两个字符串。 例如如何在一个字符串中搜索两个字符串?
$string = "The quick brown fox jumped over a lazy cat";
if($string contains both brown and lazy){
then execute my code
}
我试图pregmatch这样,
if(preg_match("/(brown|lazy)/i", $string)){
execute my code
}
但是它进入如果如果它们中的一个存在于串中循环。但是我希望它只在两个字符串出现在父字符串中时才输入if条件。我怎样才能做到这一点。
注意:我不想在字符串上循环。 (就像使用strpos
explode
字符串和foreach
分解的阵列上和搜索)
'$ string contains the brown and lazy'这里的关键字是:'和'。 – Shomz 2014-10-30 05:21:47
'$ regex =“/(brown)[^。] *(懒惰)/ i”;'要短得多。 – 2014-10-30 05:24:41
如果你正在寻找一种方法来处理正则表达式,这篇文章解释了如何用正则表达式获得'和'效果:http://stackoverflow.com/questions/469913/regular-expressions-is-there -an-and-operator – Tim 2014-10-30 05:24:44