问题
I'm using cURL
to submit a form and to do that I'm using PHP's http_build_query()
to form a query string. I was wondering why the form didn't submit and then I echoed out the query string only to find a '¶' and a 'ð` in the query string.
$post_data = array('terms' => 'true',
'ethnicity' => 0,
'param0' => 'Lance',
'param1' => 'Newman');
$post_data = http_build_query($post_data);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
echo $post_data;
Returns
terms=trueðnicity=0¶m0=Lance¶m1=Newman
I tried putting
header('Content-Type: text/html; charset=utf-8');
at the top of the page with no luck
回答1:
The character sequences ð
and ¶
are being interpreted by your browser as malformed character escape sequences (ð
for ð and ¶
for ¶).
If you want to print the query in an HTML document, run it through htmlspecialchars()
first.
来源:https://stackoverflow.com/questions/25589875/http-build-query-putting-strange-chars-in-query-string