PHP htmlentities输出不正确


PHP htmlentities output not correct

我正在尝试建立一个网站,列出poi位置。

我一直在使用谷歌PHP MySQL商店定位器教程,但仍然有一些问题。

第一个问题是将MYSQL数据库中的字符串转换为与XML

兼容的格式

我有一个记录,其中POI的名称是' ssamri ',重音是' s '

我用它来提取名称:

$newnode->setAttribute("name", htmlentities($row['Name'], ENT_SUBSTITUTE, "ISO-8859-15"));

但是它输出:

S& amp;eacute;vrier

(我不得不在&和amp来表达我的意思但是我期待

"S& eacute;vrier"

我做错了什么?

我相信这是@MichaelRushton建议使用DOMDocument做的事情

如果我只是将结果输出为html表格格式,我将得到预期的结果

// Iterate through the rows, adding XML nodes for each
echo "<table>";
while ($row = @mysql_fetch_assoc($result)){
echo "<tr>";
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("id", $row['ID']);
echo "<td>". $row['ID']."</td>";
$newnode->setAttribute("name", htmlentities($row['Name'], ENT_QUOTES, "ISO-8859-15"));
echo "<td>".$row['Name']."</td>";
$newnode->setAttribute("type", $row['Type']);
echo "<td>".$row['Type']."</td>";
$newnode->setAttribute("lat", $row['Latitude']);
echo "<td>".$row['Latitude']."</td>";
$newnode->setAttribute("lng", $row['Longitude']);
echo "<td>".$row['Longitude']."</td>";
$newnode->setAttribute("distance", $row['distance']);
echo "<td>".$row['distance']."</td>";
echo "</tr>";
}
echo "</table>";
echo $dom->saveXML();

再次阅读教程它确实建议

注意:如果您的数据库包含国际字符,或者您需要强制使用UTF-8输出,您可以对输出数据使用utf8_encode

但是我不知道如何为XML

强制UTF-8输出