Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP在不自动解码的情况下获取http url参数_Php_Http_Get - Fatal编程技术网

使用PHP在不自动解码的情况下获取http url参数

使用PHP在不自动解码的情况下获取http url参数,php,http,get,Php,Http,Get,我有一个像 test.php?x=hello+world&y=%00h%00e%00l%00l%00o 当我把它写入文件时 file_put_contents('x.txt', $_GET['x']); // -->hello world file_put_contents('y.txt', $_GET['y']); // -->\0h\0e\0l\0l\0o 但我需要不编码地将它写入 file_put_contents('x.txt', ????); // -->

我有一个像

test.php?x=hello+world&y=%00h%00e%00l%00l%00o
当我把它写入文件时

file_put_contents('x.txt', $_GET['x']); // -->hello world
file_put_contents('y.txt', $_GET['y']); // -->\0h\0e\0l\0l\0o 
但我需要不编码地将它写入

file_put_contents('x.txt', ????); // -->hello+world
file_put_contents('y.txt', ????); // -->%00h%00e%00l%00l%00o
我该怎么办


谢谢

,因为
$\u GET
$\u请求
超全局是通过一个解码函数自动运行的(相当于
urldecode()
),您只需重新编译
urldecode()
数据,使其与URL字符串中传递的字符相匹配:

file_put_contents('x.txt', urlencode($_GET['x'])); // -->hello+world
file_put_contents('y.txt', urlencode($_GET['y'])); // -->%00h%00e%00l%00l%00o
我已经在本地测试过了,它工作得非常好。但是,从您的评论中,您可能还需要查看编码设置。如果
urlencode($\u GET['y'])
的结果是
%5C0h%5C0e%5C0l%5C0l%5C0o
,则您传入的
空字符(
%00
)似乎被解释为文字字符串
“\0”
(类似于连接到
0
字符的
\/code>字符)而不是将
\0
正确解释为单个空字符


您应该看看。

我认为您可以使用
urlencode()
在URL中传递值,并使用
urldecode()
获取值。

您可以从$\u服务器[“QUERY\u STRING”]变量获取未编码的值

function getNonDecodedParameters() {
  $a = array();
  foreach (explode ("&", $_SERVER["QUERY_STRING"]) as $q) {
    $p = explode ('=', $q, 2);
    $a[$p[0]] = isset ($p[1]) ? $p[1] : '';
  }
  return $a;
}

$input = getNonDecodedParameters();
file_put_contents('x.txt', $input['x']); 

不工作。它返回x-->你好+世界,y-->%5C0h%5C0e%5C0l%5C0l%5C0o@user1725661-然后发生了别的事情。我刚测试过这个,效果很好。。。请看我的扩展答案。不起作用。它返回x-->hello+world,y-->%5C0h%5C0e%5C0l%5C0l%5C0这是正确的答案,因为Ben D建议的重新编码对某些字符(如斜杠)的处理方式不同。