2011-06-20 62 views
4

因此,我有一个小的PHP脚本,可以为我的博客的RSS源生成xml感觉。然而,它抛出了这个错误:PHP生成RSS XML - 编码错误

This page contains the following errors:

error on line 23 at column 14: Encoding error
Below is a rendering of the page up to the first error.

(这里看到:http://aviatex14.co.uk/rss.xml

下面是产生它的代码:

while ($line = mysql_fetch_array($result)) { 
    $return[] = $line; 
    var_dump(date("Y-m-d H:i:s", $line['timestamp'])); 
} 

$now = date("D, d M Y H:i:s T"); 

$output = "<?xml version=\"1.0\" encoding=\"UTF-16\" ?> 
      <rss version=\"2.0\"> 
       <channel> 
        <title></title> 
        <link></link> 
        <description></description> 
        <pubDate></pubDate> 
        <language>en-us</language> 

        <lastBuildDate>$now</lastBuildDate> 
      "; 

foreach ($return as $line) { 
    $output .= "<item><title>".htmlentities($line['title'])."</title> 
       <link>http://blog.aviatex14.co.uk/permalink.php?uid=".htmlentities($line['uid'])."</link>  
       <description>".htmlentities(strip_tags($line['entry']))."</description> 
       <pubDate>".$date = date("Y-m-d H:i:s T", $line['timestamp'])."</pubDate> 
       </item>"; 
} 
$output .= "</channel></rss>"; 
print "Content-Type: application/rss+xml"; 
echo $output; 

$f = fopen("rss.xml", "w"); 
fwrite($f, $output); 
fclose($f); 

任何帮助,将不胜感激! :D

+0

我想知道什么'htmlentities'在其他地方使用。无论如何,你应该提供一个'charset'来使它至少为它自己工作:http://php.net/manual/en/function.htmlentities.php – hakre

+0

'encoding = \“UTF-16 \”' - 这是真的是输出的真正的编码? – hakre

+0

这条线没有错误了。显然,OP在询问后更改了Feed。投票结束。 – Gordon

回答

6

它在那条线上说“TOKYO 一个日本人”(并且进一步在饲料中也是如此)。 不是utf-8。尝试utf8_encode(或iconv,如果您想要不同的编码)内容或甚至更好:use an XML processor来创建Feed。

+0

XML以UTF-16编码呈现,而不是UTF-8。 – hakre

+0

@hakre然后OP在我回答时改变了。当我下载饲料时,它肯定是utf8。我已经添加iconv作为附加解决方案。 – Gordon

+0

作品,在给我这个问题的程度上...第157行第33行的错误:打开和结束标记不匹配:第0行和描述....我宁愿不必回去修复标记:( – AviateX14