Can you please tell me how can I use strops
to see if a string doesn't contains any of the two specific words? (?
and 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”;
}
strpos()
does not support regular expression. So you either use regexps (like preg_match()
or do something less sophisticated like:
$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);
if ((strpos($phrase, "?")===FALSE)$$(strpos($phrase,"if")===FALSE)) echo "neither word is found";