doule6314 2011-07-21 12:39
浏览 92
已采纳

字符编码问题 - UTF-8 /在互联网上传输数据时出现问题?

I've got data being sent from a client side which is sending it like this:

// $booktitle = "Comí habitación bailé"

$xml_obj = new DOMDocument('1.0', 'utf-8');

// node created with booktitle and added to xml_obj 
// NO htmlentities / other transformations done

$returnHeader = drupal_http_request($url, $headers = array("Content-Type:  text/xml; charset=utf-8"), $method = 'POST', $data = $xml_data, $retry = 3);

When I receive it at my end (via that drupal_http_request) and I do htmlentities on it, I get the following:

 Comí habitación bailé

Which when displayed looks like gibberish:

 Comí Habitación Bailé

What is going wrong?


Edit 1)

<?php
$title = "Comí habitación bailé";
echo "title=$title
";
echo 'encoding is '.mb_detect_encoding($title);
$heutf8 = htmlentities($title, ENT_COMPAT, "UTF-8");
echo "heutf8=$heutf8
";
?>

Running this test script on a Windows machine and redirecting to a file shows:

title=Comí habitación bailé
encoding is UTF-8heutf8=

Running this on a linux system:

title=Comí habitación bailé
encoding is UTF-8PHP Warning:  htmlentities(): Invalid multibyte sequence in argument in /home/testaccount/public_html/test2.php on line 5
heutf8=
  • 写回答

3条回答 默认 最新

  • dops57958 2011-07-21 13:01
    关注

    htmlentities interprets its input as ISO-8859-1 by default; are you passing UTF-8 for the charset parameter?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器