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 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程