0
我想用php SimpleXMLElement
創建sitemap.xml文件。但我有一個問題,當我的鏈接包含波斯語(波斯語)的語言。輸出文件改變了問號(????)。如何通過php保存帶有UTF-8的xml文件SimpleXMLElement
如何使用utf-8保存xml文件?SimpleXMLElement
?
我的樣本代碼:
$a='<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>www.example.com/page-test/صفحه-تست/</loc>
<changefreq>daily</changefreq>
<priority>0.95</priority>
</url>
</urlset>';
$xml= new SimpleXMLElement($a);
$xml->asXML("sitemap.xml");
了出來把這樣的:
<loc>www.example.com/page-test/?????-?????/</loc>
您會解釋downvote的原因 –
他使用SimpleXML。你的回答沒有解決問題 – Machavity
雖然是xml,但它也是php類,爲什麼我可以調用php函數urlencode()? –