我得到了从客户端发送的数据,它是这样发送的:
// $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);当我在我的结尾(通过那个drupal_http_request)接收到它并且在它上做When实体时,我得到以下信息:
Comí habitación bailé当显示时看起来像是胡言乱语:
Comà Habitación Bailé出什么问题了?
编辑1)
<?php
$title = "Comí habitación bailé";
echo "title=$title\n";
echo 'encoding is '.mb_detect_encoding($title);
$heutf8 = htmlentities($title, ENT_COMPAT, "UTF-8");
echo "heutf8=$heutf8\n";
?>在Windows机器上运行此测试脚本并重定向到文件如下:
title=Comí habitación bailé
encoding is UTF-8heutf8=在linux系统上运行此程序:
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=发布于 2011-07-21 13:01:47
默认情况下,htmlentities将其输入解释为ISO-8859-1;您是否为字符集参数传递UTF-8?
发布于 2011-07-21 12:42:56
我认为您不应该仅仅为了正确输出而用meta实体对实体进行编码(如注释中所述,您应该使用htmlspecialchars来避免跨端脚本编写),只需设置正确的头和元尾,通常会得到以下值:
<?php
header ('Content-type: text/html; charset=utf-8');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
</body>
</html>发布于 2011-07-21 12:53:35
尝试以键/值数组格式传递标头信息。
有点像
$headers = array("Content-Type" => "text/xml; charset=utf-8"")
https://stackoverflow.com/questions/6776179
复制相似问题