I use the "OR" operator "|" to match one of the words of the $name variable:
$name = "one five six two";
if (preg_match('/(one|two)/i', $name)) {return true;}
What operator should I use with preg_match to have an "AND" condition if those words are inside of $name?
For example,
if (preg_match('/(two "AND" five)/i', $name)) {return true;}
If you still want to use regex, you'll need positive lookaheads:
if (preg_match('/^(?=.*one)(?=.*two)/i', $name)) {return true;}
It's not recommended for simple stuff (kind of overkill), and it gets messy with more complex stuff...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With