title: parse search string
body: <p>I have search strings, similar to the one bellow:</p>
  
  <pre><code>energy food "olympics 2010" Terrorism OR "government" OR cups NOT transport
  </code></pre>
  
  <p>and I need to parse it with PHP5 to detect if the content belongs to any of the following clusters:</p>
  
  <ul>
  <li>AllWords array</li>
  <li>AnyWords array</li>
  <li>NotWords array</li>
  </ul>
  
  <p>These are the rules i have set:</p>
  
  <ol>
  <li>If it has OR before or after the word or quoted words if belongs to
  AnyWord.</li>
  <li>If it has a NOT before word or quoted words it belongs to NotWords</li>
  <li>If it has 0 or more more spaces before the word or quoted phrase it
  belongs to AllWords.</li>
  </ol>
  
  <p>So the end result should be something similar to:</p>
  
  <pre><code>AllWords: (energy, food, "olympics 2010")
  AnyWords: (terrorism, "government", cups)
  NotWords: (Transport)
  </code></pre>
  
  <p>What would be a good way to do this?</p>