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

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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;

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.