So I have a small PHP script that generates an xml feel for the rss feed of my blog. However, it throws up this error:
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.
(seen here: http://aviatex14.co.uk/rss.xml)
Here's the code that generates it:
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);
?>
Any help would be appreciated! :D
htmlentities
is used everywhere therein. Anyway, you should provide acharset
to make it work for itself at least: php.net/manual/en/function.htmlentities.php – hakre Jun 20 '11 at 19:52encoding=\"UTF-16\"
- is this really the output's true encoding? – hakre Jun 20 '11 at 19:53