【问题标题】:http_build_query putting strange chars in query stringhttp_build_query 在查询字符串中放入奇怪的字符
【发布时间】:2014-08-31 07:31:55
【问题描述】:

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

$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');

在页面顶部没有运气

【问题讨论】:

  • php文件也保存为UTF8?

标签: php character-encoding query-string


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2019-11-20
    • 2021-04-23
    相关资源
    最近更新 更多