parse_str() - problem with semicolon

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ArmanX
Forum Newbie
Posts: 2
Joined: Mon Feb 08, 2010 7:13 am

parse_str() - problem with semicolon

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: parse_str() - problem with semicolon

Post 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).
ArmanX
Forum Newbie
Posts: 2
Joined: Mon Feb 08, 2010 7:13 am

Re: parse_str() - problem with semicolon

Post by ArmanX »

Thanks for your help.
Post Reply