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.
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().
<?php
$str='a=123&b=456&Signature=aaaa/bbb+i8=&Satus=bbbb';
$new_string = str_replace('+', '.', $str);
parse_str($new_string,$old_string);
$signature = str_replace('.', '+', $old_string['Signature']);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With