具有相同标识符的多个 HTTP GET 参数 [英] Multiple HTTP GET parameters with the same identifier

查看:30
本文介绍了具有相同标识符的多个 HTTP GET 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我收到如下请求:

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 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆