Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Stripping Google results out of Referer Value

0 views
Skip to first unread message

Chip Wood

unread,
Oct 9, 2002, 5:30:06 PM10/9/02
to
How would I go about isolating the term that was used in the Google search
term that is passed on through the $HTTP_REFERER value?


The typical format of the string is as follows:
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=SOME+SEARCH+TERM&
btnG=Google+Search


-Chip Wood


Ewgenij Starostin

unread,
Oct 9, 2002, 8:32:54 PM10/9/02
to
Chip Wood wrote:

> How would I go about isolating the term that was used in the Google
> search term that is passed on through the $HTTP_REFERER value?

> http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=SOME+SEARCH+
> TERM&btnG=Google+Search

This is best done with a regexp. Since I can't write them, a more
conventional solution follows.

list( $scheme, $host, $port, $user, $pass, $path, $query, $fragment ) =
parse_url( $_SERVER[ 'HTTP_REFERER' ] );
$query_args = explode( '&', $query );

function proc_query_arg( $val, $key, &$new_array )
{
list( $new_key, $new_val ) = explode( '=', $val );
$new_array[ $new_key ] = $new_val;
}

$query = array();
array_walk( $query_args, 'proc_query_arg', $query );

echo str_replace( '+', ' ', $query[ 'q' ] );

--
Some people say that dying is hazardous for one's health.
Others say that nothing can travel faster than light.
I wonder what the logical connection between these statements is.

jbp

unread,
Oct 9, 2002, 9:30:37 PM10/9/02
to

| $url = "http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=SOME+SEARCH+TERM&btnG=Google+Search";
| preg_match("|q=([^&]*)&?.*$|i", $url, $match);
| $term = $match[1];
| $term = urldecode($term);
| echo "search term was '{$term}'";

--
Joseph Birr-Pixton

Mark Young

unread,
Oct 9, 2002, 10:59:40 PM10/9/02
to

"Chip Wood" <invs...@mail.com> wrote in message
news:yd1p9.1727$qW4.5...@newssrv26.news.prodigy.com...

http://www.php.net/manual/en/function.urldecode.php


Chip Wood

unread,
Oct 11, 2002, 10:52:05 AM10/11/02
to
"jbp" <m...@ifihada.com> wrote in message
news:fjl9quc3dr03aoc5j...@4ax.com...


Worked like a charm.

Thanks!


0 new messages