【发布时间】:2017-05-15 17:21:58
【问题描述】:
我想用 php SimpleXMLElement 创建 sitemap.xml 文件。但是当我的链接包含波斯语(波斯语)语言时,我遇到了问题。输出文件将 persain 字改为问号 (????)。
我如何通过SimpleXMLElement 保存带有 utf-8 的 xml 文件?
我的示例代码是:
$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>
【问题讨论】: