Extract Search Keywords from String





4
Date Submitted Wed. Jul. 4th, 2007 8:50 AM
Revision 1 of 1
Beginner drillman
Tags "extract keywords" | "search string" | google
Comments 2 comments
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") ;
 

Comments

Comments register_globals
Thu. Jul. 5th, 2007 9:56 AM    Helper Nico
  Comments If register global is off
Thu. Jul. 19th, 2007 11:52 PM    Syntax Master sundaramkumar

Voting

Votes Down