http_build_query putting strange chars in query string

♀尐吖头ヾ 提交于 2020-01-06 03:57:13

问题


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 &eth and &para 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!