使用PHP从(搜索引擎)引荐来源网址获取关键字 [英] Get keyword from a (search engine) referrer url using PHP
本文介绍了使用PHP从(搜索引擎)引荐来源网址获取关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从引荐来源网址获取搜索关键字.目前,我将以下代码用于Google网址.但是有时候它不起作用...
I am trying to get the search keyword from a referrer url. Currently, I am using the following code for Google urls. But sometimes it is not working...
$query_get = "(q|p)";
$referrer = "http://www.google.com/search?hl=en&q=learn+php+2&client=firefox";
preg_match('/[?&]'.$query_get.'=(.*?)[&]/',$referrer,$search_keyword);
还有其他/清洁/可行的方法吗?
Is there another/clean/working way to do this?
谢谢你, 普拉萨德
推荐答案
如果您使用的是PHP5,请查看 http: //php.net/parse_url 和 http://php.net/parse_str
If you're using PHP5 take a look at http://php.net/parse_url and http://php.net/parse_str
示例:
// The referrer
$referrer = 'http://www.google.com/search?hl=en&q=learn+php+2&client=firefox';
// Parse the URL into an array
$parsed = parse_url( $referrer, PHP_URL_QUERY );
// Parse the query string into an array
parse_str( $parsed, $query );
// Output the result
echo $query['q'];
这篇关于使用PHP从(搜索引擎)引荐来源网址获取关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文