问题描述
我需要检测引用我网站的搜索引擎.由于每个搜索引擎都有不同的搜索查询字符串(例如,google 使用q=',yahoo 使用 'p='),我使用它们的 url 正则表达式模式为搜索引擎创建了一个数据库.
I need to detect search engines that refers to my website. Since every search engine has different query strings for searching(e.g. google uses 'q=', yahoo uses 'p=') I created a database for search engines with their url regex patterns.
我为谷歌创建的正则表达式是:
the regex I created for google is:
(http:)(\\/)(\\/)(www)(\\.)(google)(\\.).*(\\/)(search).*(&q=|\\?q=).*
(我是正则表达式的新手,但到目前为止它有效)
(I am a newbie on regex, but so far it works)
这会检测到该网址属于 Google.我的问题是我需要从上面的 url 或其他搜索引擎中提取搜索词.但我不知道如何将它与正则表达式匹配.我尝试使用 PHP 函数从 url 中提取查询字符串并将其与模式匹配,但它什么也没返回.
This detects that the url belongs to Google.My problem is that I need to extract the search words from the url above or from other search engines. But I dont know how to match it with the regular expression. I have tried extracting the query string from the url by using PHP functions and match it against the pattern, but it returned nothing.
希望我能解释得足够清楚.
Hope I could explain this clear enough.
有什么建议吗?
推荐答案
这个 有关从引荐来源网址中提取关键字的博客条目 似乎非常适合解决您的问题.
This blog entry about extracting keywords from the referrer seems like it is a good match for solving your problem.
我使用这个搜索找到了它'从谷歌引用网址中提取查询字符串'.搜索似乎有许多有用的点击...我只是扫了前几个.
I found it using this search for 'extract query string from google referer url'. The search seems to have a number of helpful hits... I just did a sweep of the first few.
这篇关于正则表达式检测搜索引擎和搜索词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!