0

你能告诉我如何使用strops来查看字符串是否不包含两个特定单词中的任何一个吗?(?if)

$phrase = “how to use strops?”
if(strpos($phrase, "?|if") === false) //Is there a way I can detect the presence of
{               //either words in a sentence using one line of code that has strpos

     echo “neither word is found”;
}
4

2 回答 2

2

strpos()不支持正则表达式。所以你要么使用正则表达式(比如preg_match()或者做一些不太复杂的事情,比如:

$phrase = "how to use strpos";
$words = array('foo', 'bar');

$matches = 0;
foreach( $words as $word ) {
   $matches += ( strpos( $phrase, $word ) !== false ) ? 1 : 0;
}

printf("%d words matches", $matches);
于 2013-07-02T14:27:17.163 回答
-2
if ((strpos($phrase, "?")===FALSE)$$(strpos($phrase,"if")===FALSE)) echo "neither word is found";
于 2013-07-02T14:37:03.620 回答