dousikuai5417 2017-12-04 03:29 采纳率: 0%
浏览 128
已采纳

php parse_str将plus(+)转换为空格

I'm using parse_str to get an array from a string, which is like:

$str='a=123&b=456&Signature=aaaa/bbb+i8=&Satus=bbbb';

I noticed that the function parse_str does convert plus to space, but how can I avoid this things.

new edit:
The $str to a value that I get from a string which is like this:

YT0xMjMmYj00NTYmU2lnbmF0dXJlPWFhYWEvYmJiK2k4PSZTYXR1cz1iYmJi

I get the string and make base64_decode,then get the $str.

  • 写回答

4条回答 默认 最新

  • duancan65665 2017-12-04 03:52
    关注

    That's because parse_str() expects a URL-encoded string as its first argument or, more specifically, a query string which is of mime-type application/x-www-form-urlencoded.

    For historical reasons a +-sign, besides its percent-encoded counterpart %20, is also interpreted as a space, in the context of this mime-type. Wikipedia has this to say about this:

    The application/x-www-form-urlencoded type


    [...] The encoding used by default is based on an early version of the general URI percent-encoding rules, with a number of modifications such as newline normalization and replacing spaces with + instead of %20. [...]

    So, you need to make sure you feed parse_str() a properly URL-encoded string to get the characters that you expect. If you expect a + it should first be properly percent-encoded as %2B, before you pass it to parse_str().

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

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿