Does anyone know of any pre-built functions out there to parse the search query used to get to your site? I'm going to build a function to do it, but would certainly love to save myself the time if it already exists. I need to determine whether they came from natural search vs paid as well
yes, that sort of functionality, but I want to create a PHP function to do it, so I can track leads by their search engine source
Untested. $ref = @parse_url($_SERVER['HTTP_REFERER']); if (preg_match('/(google|yahoo|msn)\.[a-z]{2,4}/$', $ref['host'], $engine)) { @parse_str($ref['query'], $query); $request = $engine[1] == 'yahoo' ? $query['p'] : $query['q']; if (!empty($request)) { $keywords = preg_split('/[\+\s]/', $request); print_r($keywords); } } PHP:
very slick. Now I suppose that if you wanted to parse for all search engines you could use a switch case instead of this line, correct? $request = $engine[1] == 'yahoo' ? $query['p'] : $query['q']; PHP:
I know that someone, somewhere, has written some code for this. I know this because I remember seeing it linked either here or on another forum. I can't for the life of me find it, though... suffice to say there is code out there: just keep looking