parse_str prepending ampersand to elements?
I've been playing around with cURL, and am trying to send an array through as POST variables. I've decided to use http_build_query to pass the string as expected:
curl_setopt($this->ch, CURLOPT_POSTFIELDS, http_build_query($sendParams));
I have the receiving end simply print_r
'ing the $_POST, so I can see what is being sent through.
However, I am getting an ampersand attached to all of the parent elements after the first, is this normal? I assume that parse_str is used by开发者_JS百科 cURL when parsing the querystring, so here is a super-simplified example that also leads to the ampersands:
<?php
$array = array('foo', array('bar' => array('baz' => array(1,2,3))), 'test' => array(2,3,4));
parse_str(http_build_query($array), $vars);
print_r($vars);
?>
Returns:
Array ( [0] => foo [amp;1] => Array ( [bar] => Array ( [baz] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) ) [amp;test] => Array ( [0] => 2 [1] => 3 [2] => 4 ) )
Seem to have answered my own question... parse_str
is confused by &, and I need to run html_entity_decode
first, before parsing the querystring.
精彩评论