假设我收到如下请求:
http://www.example.com/index.php?id=123&version=3&id=234&version=4
是否可以在我的 php 代码中以简单的方式提取这些内容?我意识到我可以使用 window.location.href 使用 javascript 获取整个查询字符串并手动处理它,但我正在寻找更优雅的东西.请求可以包含任意数量的版本/ID 对,但我可以假设查询格式正确并且没有义务处理无效字符串.
Is it possible to extract these in a simple way inside my php code? I realize I could get the entire querystring with javascript using window.location.href and handle it manually but I'm looking for something more elegant. The requests can contain any number of version/id pairs but I can assume that the query is well-formed and have no obligation to handle invalid strings.
根据 PHP 手册中的这条评论,PHP 的查询字符串解析器将删除重复的参数......所以我认为 PHP 不适合你想做的事情(除了它有与 javascript 获取原始查询字符串的能力相同,您可以使用它做任何您想做的事)
According to this comment from the PHP manual, PHP's query string parser will drop duplicate params... so I don't think that PHP is a good fit for what you want to do (except in that it has the same capacity as javascript to get the raw query string, with which you can do whatever you want)
这篇关于具有相同标识符的多个 HTTP GET 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!