在PHP中,如果我有以下脚本:
var_dump($_REQUEST);
Run Code Online (Sandbox Code Playgroud)
如何区分以下请求:
GET /foo?hello%20dude=cool
GET /foo?hello_dude=cool
Run Code Online (Sandbox Code Playgroud)
他们都打印:
array(1) { ["hello_dude"]=> string(4) "cool" }
Run Code Online (Sandbox Code Playgroud)
因为密钥名称不允许有空格?我是否必须手动解析POST数据以及GET数据,还是有更简单的方法?
我认为您将不得不绕过 PHP 对查询字符串的自动解析并自己完成。
您可以通过检查获取完整的请求 URI $_SERVER['REQUEST_URI']。从那里,您可以拆分第一个问号?,然后拆分 & 符号&,然后将每个拆分=。可能还有一个方便的正则表达式解决方案。