Error in php parse_str function with Special character

Asked

Viewed 98 times

2

I’m trying to use the function parse_str php string a value with the character +, but the result returns me to string without that character, see:

parse_str("c=item1 + item2");
var_dump($c);

2 answers

3

That is the scope

void parse_str ( string $encoded_string [, array &$result ] )

Therefore, encode the non-ascii characters before passing the function:

parse_str(urlencode('c=item1 + item2'));

There are other peculiarities about this function. See the manual for more: http://php.net/manual/en/function.parse-str.php

  • I could not solve this way, it does not execute the function if I encode the string as you passed

  • I was able to solve by encoding only the value in the string

0

The case was solved that way:

$str = urlencode('item1 + item2');
parse_str("c={$str}");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.