我正在尝试创建一个脚本来将我的注释导出到Disqus,为了做到这一点,我需要创建一个巨大的XML文件。由于错误的UTF8编码导致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到一个文件。
你知道应该是什么问题吗?
我从fwrite创建文件,所以它似乎没有用UTF-8编码它,它确实有UTF8声明,但它不是UTF8编码。我打开并用Notepad ++将XML文件重新编码为UTF8,保存并解决。我怎样才能在PHP脚本上做到这一点? – 2011-05-06 19:13:29