TecTao Posted June 19, 2007 Share Posted June 19, 2007 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 https://forums.phpfreaks.com/topic/56276-solved-strip-letters-and-words-from-http_referer/ Share on other sites More sharing options...
siwelis Posted June 19, 2007 Share Posted June 19, 2007 $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 https://forums.phpfreaks.com/topic/56276-solved-strip-letters-and-words-from-http_referer/#findComment-278006 Share on other sites More sharing options...
GingerRobot Posted June 19, 2007 Share Posted June 19, 2007 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 https://forums.phpfreaks.com/topic/56276-solved-strip-letters-and-words-from-http_referer/#findComment-278011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.