I want to make a PHP script that takes a PHP GET variable $_GET[q] made up of many different words or terms and checks to see if it contains any “keywords” that are stored in an array. An example of this would be It could look like “What time is it in San Francisco”. I would want the script to pick up on “time” and “san francisco” as an example. I have played about with using
if(stripos($_GET[q],'keyword1','keyword2'))
but haven’t had much luck.
Does anyone know how I could do this?
I hope everyone can understand what I am trying to describe.
You can make an array of keywords, then loop though until you find a match.
UPDATE: If you want to match ALL keywords, you can do this instead:
DEMO: http://codepad.org/LaEX6m67
UPDATE 2: Because I’m crazy and like one-liners, you can do this in PHP 5.3+:
DEMO: http://codepad.viper-7.com/Y48sHR