Jump to content

[SOLVED] Strip Letters and Words from $HTTP_REFERER


TecTao

Recommended Posts

I have a little snippet of code that emails me when someone hits a page of my site.  It sends me an email with the following when the page is visited from a google search. 

 

$rhostget = $HTTP_REFERER; is the variagle with the search information.

 

For example, the following may be in the email.

 

google.com/search?q=web+site+designs&hl=en&rls=GGLR,GGLR:2005-41,GGLR:en&start=90&sa=N

 

I would like to create a variable for the $rhostget that strips everything up to the q= and after the & and the + between the search phrase words. So that what is sent is:

 

web site designs

 

Is it possible to strip all of the extra words and symbols?

 

Thanks in advance for any help.

Mike

$rhostget = str_replace("google.com/search?","",$HTTP_REFERER);

//returns  q=web+site+designs&hl=en&rls=GGLR,GGLR:2005-41,GGLR:en&start=90&sa=N

$rhostget = str_replace("+","",$rhostget);

//returns q=websitedesigns&hl=en&rls=GGLR,GGLR:2005-41,GGLR:en&start=90&sa=N

 

Strip out whatever you like... using that....

 

Another option (which I don't know the syntax for or I'd post it for you) is to store the HTTP_REFERER in an array, and select characters only to a certain number or "until" a "&" is come across

I think i'd go for a preg_match and a str_replace:

 

<?php
$str = 'google.com/search?q=web+site+designs&hl=en&rls=GGLR,GGLR:2005-41,GGLR:en&start=90&sa=N';
$search_term= preg_match('|\?q=(.*?)\&|',$str,$matches);
$search_term = str_replace('+',' ',$matches[1]);
echo $search_term;

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.