Re: Parsing search strings from referer urls?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



T.J. Mahaffey wrote:
First time post, please be gentle.

I'd like to be able to extract search strings from referer urls that come from search engines. (via php,
of course) For example, http://www.google.com/search?q=foo+bar&ie=UTF-8&oe=UTF-8

Now, I realize one might employ grep to pull out this information and its easy for a human to examine
a url like the one above, but I'd like to programmatically present a nice, tidy list of search words used
to generate the url.

My gut says that one would need to write a function for each major search engine to parse out this
information since each engine is unique in how it builds the url. However, I thought after poring over
the manual and online docs/list and not finding a solution, and before I went off and reinvented the
wheel, I would float the question and see what you fine folks have to say about the subject.

You will probably find parse_url() to be useful: http://www.php.net/manual/en/function.parse-url.php

<?php

$url = "http://username:password@hostname/path?arg=value&arg2=value&arg3=value3#anchor";;

$parts = parse_url($url);
$args = explode('&', $parts['query']);

for($i = 0; $i < sizeof($args); $i++) {
  list($key, $value) = explode('=', $args[$i]);
  $query[$key] = urldecode($value);
}

print_r($query);

?>


-- Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY | http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux