Extract Search Keywords from String
4
drillman
This snippet extracts the keywords or search phrases from a Google referral. It also sets variables for the search engine, date and web page which received the referral if you want to log the data to a file or database. The variables are $engine, $finalphrase (keyword phrase), $page(referred web page), and $date.
unset ($engine);
$string = $HTTP_REFERER;
if (strstr($string, "google")){
if (strstr($string, "search?")) {
$engine = "google";
$substr = explode("q=", $string);
$substr = explode("&", $substr[1]);
$kwphrase = eregi_replace("(%[0-9a-f]{2})+", " ", $substr[0]);
$kwphrase = eregi_replace("(\+)+", " ", $kwphrase);
$finalphrase = strtolower($kwphrase);
}
$to = explode("/", $PHP_SELF);
$arraynum = count ($to);
$page = $to[$arraynum-1];
$date = date("Y-n-j") ;





Also, have a look at parse_str() and rawurldecode().
You have to change the code by using $_REQUEST to make it work.
This is piece is an nice one. Good Job
Regards,
Kumar S
GuyFromChennai.com