Page 1 of 1

parse_str() - problem with semicolon

Posted: Mon Feb 08, 2010 7:33 am
by ArmanX
Hi,

I have a strange problem with function parse_str(). It works fine everywhere, except one server (PHP 5.2.6).

Code example:

Code: Select all

 
$str = 'values=3;5;2&x=43';
parse_str($str, $x);
echo '<pre>'; print_r($x); echo '</pre>';
 
Normal/Expected output of this script is:

Array
(
[values] => 3;5;2
[x] => 43
)

but on this one specific server the output is:

Array
(
[values] => 3
[5] =>
[2] =>
[x] => 43
)

Do you have any idea what is wrong?

Re: parse_str() - problem with semicolon

Posted: Mon Feb 08, 2010 8:38 am
by Weirdan
semicolon is a valid query parameter separator, so to use it in the parameter value you need to encode it (using urlencode() for example).

Re: parse_str() - problem with semicolon

Posted: Mon Feb 08, 2010 9:05 am
by ArmanX
Thanks for your help.