http_build_query将奇怪的字符放入查询字符串 [英] http_build_query putting strange chars in query string

查看:228
本文介绍了http_build_query将奇怪的字符放入查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 cURL 提交表单,并使用PHP的 http_build_query()形成查询字符串。我想知道为什么不提交表单,然后回显查询字符串,只是在查询字符串中找到了'¶'和'ð`。

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;

返回

terms=trueðnicity=0¶m0=Lance¶m1=Newman

我尝试放入

 header('Content-Type: text/html; charset=utf-8');

在页面顶部没有运气

推荐答案

字符序列& eth & para 是被浏览器解释为格式错误的字符转义序列(对于ð表示& eth; ,对于¶表示& para; )。

The character sequences &eth and &para are being interpreted by your browser as malformed character escape sequences (ð for ð and ¶ for ¶).

如果要在HTML文档中打印查询,请先通过 htmlspecialchars()运行查询。

If you want to print the query in an HTML document, run it through htmlspecialchars() first.

这篇关于http_build_query将奇怪的字符放入查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆