dryift6733 2013-06-21 15:02
浏览 61
已采纳

字符丢失将_GET数组转换为URL字符串

Having a very bizarre issue with the conversion of a $_GET request into a string. (PHP 5.2.17)

Here is a small snippet of the problem area of the array from print_r():

_GET (array)
  ...
  [address_country_code] => GB
  [address_name] => Super Mario
  [notify_version] => 3.7
  ...

There are two cases the _GET data is used:

Case 1): Saved then used later:

// Script1.php

$data = json_encode($_GET);
# > Save to MySQL Database ($data)


// Script2.php (For Viewing & Testing URL later)

# > Load from Database ($result)
echo http_build_query(json_decoded($result,true));

Result of above array snippet: (CORRECT OUTPUT)

address_country_code=GB&address_name=Super+Mario&notify_version=3.7

Case 2): Used in same script as Case 1) just before its saved in Case 1):

// Script1.php

echo http_build_query($_GET);

Results in: (INCORRECT OUTPUT)

address_country_code=GB&address_name=Super+Mario¬ify_version=3.7

How is it possible that a few chars are output as a ¬ in case 2 yet case 1 is fine! It is driving me insane :(

I have tried also instead of using http_build_query a custom function that generates the url using urlencode() in the Key and Value of the foreach loop, this just resulted in the the ¬ being changed to %C2%AC in one of my test cases!

  • 写回答

3条回答 默认 最新

  • drc4925 2013-06-21 15:59
    关注

    So, even though both cases output to web a web browser and both convert from an array using http_build_query().

    I fixed problem in Case 2 by replacing http_build_query (Case 1 still uses it..) with this function:

    htmlspecialchars(http_build_query($_GET));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?