parse search string
Posted
by Benjamin Ortuzar
on Stack Overflow
See other posts from Stack Overflow
or by Benjamin Ortuzar
Published on 2010-03-23T10:41:53Z
Indexed on
2010/03/23
10:43 UTC
Read the original article
Hit count: 369
I have search strings, similar to the one bellow:
energy food "olympics 2010" Terrorism OR "government" OR cups NOT transport
and I need to parse it with PHP5 to detect if the content belongs to any of the following clusters:
- AllWords array
- AnyWords array
- NotWords array
These are the rules i have set:
- If it has OR before or after the word or quoted words if belongs to AnyWord.
- If it has a NOT before word or quoted words it belongs to NotWords
- If it has 0 or more more spaces before the word or quoted phrase it belongs to AllWords.
So the end result should be something similar to:
AllWords: (energy, food, "olympics 2010")
AnyWords: (terrorism, "government", cups)
NotWords: (Transport)
What would be a good way to do this?
© Stack Overflow or respective owner