查询字符串的关键字提取器
我找到了一些用于查询字符串的关键字提取器,但它们似乎都已过时(使用已弃用的代码或根本不起作用)。
有谁知道 php 查询字符串提取器。或者我将如何构建一个函数,该函数接受“amazon.com”等“主机”和多个查询参数的名称并返回这些参数的值?
例如,http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=a+tale+of+two+cities&x=0&y= 0
如果我提供了“amazon.com”和“field-keywords”,如何获取数组:['a','tale','of','two','cities'] ?
提前致谢!!
澄清
Jose 的回答涵盖了我针对 Amazon 的示例,但似乎不适用于任何其他 URL:
http://www.bing.com/search?q=Christmas+Around+The+ World&form=QBLH&qs=PN&sk=HS1PN4&pq=&sp=6&sc=8-0
http://search.yahoo.com/search;_ylt=AnQN0c997QR5SIYcYt。 h2YCbvZx4?p=golf&toggle=1&cop=mss&ei=UTF-8&fr=yfp-t-701
I've found a few keyword extractors for query strings, but they all seem to be outdated (use deprecated code or simply don't work).
Does anyone know of a php query string extractor. Or how would I build a function that takes a "host" like "amazon.com" and the names of multiple query parameters and returns the values of those parameters?
For instance, http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=a+tale+of+two+cities&x=0&y=0
If I provided "amazon.com" and "field-keywords" how can I get the array: ['a','tale','of','two','cities']
?
Thanks in advance!!
Clarification
Jose's answer covers my example for Amazon but doesn't seem to work for any other URL:
http://www.bing.com/search?q=Christmas+Around+The+World&form=QBLH&qs=PN&sk=HS1PN4&pq=&sp=6&sc=8-0
http://search.yahoo.com/search;_ylt=AnQN0c997QR5SIYcYt.h2YCbvZx4?p=golf&toggle=1&cop=mss&ei=UTF-8&fr=yfp-t-701
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你(我)可以写一个。
只是从 @Jose 的答案中窃取了一点代码:)
更新:经过测试,不起作用,修复,起作用。
更新2:毕竟没用,经过测试、修复、有效。
更新 3:添加了对 HTTPS 的支持
You (I) could write one.
Just a tad of code stolen from @Jose's answer :)
Update: tested, didn't work, fixed, works.
Update 2: didn't work after all, tested, fixed, works.
Update 3: added support for HTTPS
这个应该可以..
This should do it..
按照我阅读问题的方式,您只需要将查询字符串索引名称传递给函数,例如......
The way I read the question, you would only need the query string index name to be passed to the function like...