我正在尝试创建一个脚本来将我的评论导出到 Disqus,为此,我需要制作一个巨大的 XML 文件。
我的 UTF 8 编码有问题。应该是 UTF-8 文件,但我需要制作 utf8_decode 才能正确显示我的西班牙语元素。
生成的文件是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dsq="http://www.disqus.com/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.0/"
>
<channel>
<wp:comment>
<wp:comment_id>26</wp:comment_id>
<wp:comment_author>KA_DIE</wp:comment_author>
<wp:comment_author_email> </wp:comment_author_email>
<wp:comment_author_url></wp:comment_author_url>
<wp:comment_author_IP> </wp:comment_author_IP>
<wp:comment_date_gmt>2009-07-16 18:53:19</wp:comment_date_gmt>
<wp:comment_content><![CDATA[WTF TEH Gladios en español <br />tnx tnx <br />me usta mucho esa web estoy pendiente mucho se su actualziacion es buen saber ke esta en español <br />x que solo entendia el 80, 90% de la paguina jiji]]></wp:comment_content>
<wp:comment_approved>1</wp:comment_approved>
<wp:comment_parent>0</wp:comment_parent>
</wp:comment>
</channel>
</rss>
出于安全原因删除数据,例如 IP 或电子邮件。如您所见,它包含“ñ”字母。但是显示的 XML 会引发错误:
XML 读取错误:组合错误
我不知道确切的翻译,但它在内容行中崩溃了。代码是这样生成的:
public function generateXmlElement (){
$xml = "<wp:comment>
<wp:comment_id>$this->id</wp:comment_id>
<wp:comment_author>$this->author</wp:comment_author>
<wp:comment_author_email>$this->author_email</wp:comment_author_email>
<wp:comment_author_url>$this->author_url</wp:comment_author_url>
<wp:comment_author_IP>$this->author_ip</wp:comment_author_IP>
<wp:comment_date_gmt>$this->date</wp:comment_date_gmt>
<wp:comment_content><![CDATA[$this->content]]></wp:comment_content>
<wp:comment_approved>$this->approved</wp:comment_approved>
<wp:comment_parent>0</wp:comment_parent>
</wp:comment>";
return $xml;
}
然后 fwrite 到一个文件。
你知道应该是什么问题吗?