I found this example on stackoverflow:
if (strpos($a,'are') !== false) {
echo 'true';
}
But how do I make it search for two words. I need something like this: if $a contains the words "are" or "be" or both echo "contains";
I tried xor and ||
Just check both words separately and use the boolean or
-operator to check if either one or both are contained in $a
:
if (strpos($a,'are') !== false || strpos($a,'be') !== false) {
echo "contains";
}
Note that due to the or
-operator, the second check (for 'be') is not performed if the first one already showed that $a
contains 'are'.