2
$post_data = array(
    'model' => 'player',
    'action' => 'buyItem',
    'params' => array('item_id'=>100, 'count'=>100)
);
$postData = http_build_query($post_data);
echo $postData;


$post_data = array(
    'model' => 'player',
    'action' => 'buyItem',
    'arams' => array('item_id'=>100, 'count'=>100)
);
$postData = http_build_query($post_data);
echo $postData;

the first output was model=player&action=buyItem¶ms%5Bitem_id%5D=100¶ms%5Bcount%5D=100. but the second output was right. so why can't I use params as the key? thanks!

1
  • I just see that in the 2nd array its arams, not params. These arrays are similar, i cant reproduce your failure. Commented Mar 7, 2014 at 9:07

1 Answer 1

2

I can reproduce this.

It seems params is being converted to &params which is being interpreted as &para (¶ - paragraph) + ms.

Your solution would be to call params something else or, do:

echo htmlspecialchars($postData);

Update.

Actually, this only seems to happen if you try and echo $postData, if you use it as part of a URL it shows up correctly.

If you do something like:

echo "<a href='www.mysite.com?" . $postData . "'>Link</a>";

you'll see what I mean.

Sign up to request clarification or add additional context in comments.

7 Comments

@Rikesh - glad it's not just my server then. ;)
@PeteR - Yeah. Though the reason is much clear in your answer, but rather I'm thinking of the cause & the solution.
I wonder what server configuration differences cause this to happen? Note that this also happens with other HTML entities such as nbsp, which results in a space in the URL...
@Rikesh: the solution would be to call params something else!
@FDL: hey, whatever works - I like easy... htmlspecialchars cures it too.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.