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
> 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.
| $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
http://www.php.net/manual/en/function.urldecode.php
Worked like a charm.
Thanks!