簡體   English   中英

PHP htmlentities輸出不正確

[英]PHP htmlentities output not correct

我正在嘗試建立一個列出poi位置的網站。

我一直在使用Google PHP MySQL商店定位器教程,但仍然有一些問題。

第一個問題是將字符串從MYSQL數據庫轉換為與XML兼容的格式

例如

我有一條記錄,其中POI的名稱為'Sérvier',並在é上加上了重音

我用它來提取名稱:

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

但是它輸出:

S& amp;eacute;vrier

(我必須在&和放大器之間添加空格以顯示我的意思,但我期望

"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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM