Error parse_str function in php with special character

2

I'm trying to use the parse_str function of php by stringing a value with the + character, but the result returns me the string without that character, see: p>

parse_str("c=item1 + item2");
var_dump($c);
    
asked by anonymous 22.02.2017 / 17:16

2 answers

3

This is the scope

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

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

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

There are other peculiarities about this function. See the manual to learn more: link

    
22.02.2017 / 17:22
0

The case has been resolved this way:

$str = urlencode('item1 + item2');
parse_str("c={$str}");
    
22.02.2017 / 18:58