0

I'm trying to search through some files in PHP and I want to give the user a choice between matching any or every term.

E.g.: Search terms: [apple,banana]

Is it possible to return only files that have both words in it?

Also my OR would use the following:

$s_terms = "(" . implode("|", explode(",", $s_terms)) . ")";

I want to separate terms with , and use it in a RegEx match like (apple|banana). Does the above code do that?

Thank you in forward

EDIT:

The other question did not answer my question, but I found something that works: (.*apple.*banana.*)

WolfyD
  • 865
  • 3
  • 14
  • 29
  • 1
    Your code correctly converts `a,b` into `(a|b)`. But that will match files with any of the words, it won't require that they have ALL the words. – Barmar Jun 26 '15 at 12:55
  • @Barmar That is what I guessed, but Is there a way to look for ALL the words, or will I have to separately match every word in the file? – WolfyD Jun 26 '15 at 12:57
  • @Barmar Thanks for your help – WolfyD Jun 26 '15 at 13:06

0 Answers0