custom rss feed suddenly does not work anymore
I just don't understand what's happening, I haven't change anything to the site for a few months but now suddenly the rss feed doesn't work anymore.
I create a php file with the following code:
header('Content-type: text/xml');
include("config/config.inc.php");
$result = mysqli_query($link, "SELECT * FROM tutorials ORDER BY tutorial_id DESC LIMIT 50");
?>
<rss version="2.0">
<channel>
<title>CMS tutorial site</title>
<description>Bringing you the best CMS tutorials from the web</description>
<link>http://cmstutorials.org</link>
<?php
while($row = mysqli_fetch_object($result))
{
$user = mysqli_fetch_object(mysqli_query($link, "SELECT * FROM user_extra WHERE userid=".开发者_运维知识库$row->user_id.""));
?>
<item>
<title><?php echo $row->title; ?></title>
<author><?php echo $user->username; ?></author>
<description><?php echo $row->description; ?></description>
<pubDate><?php echo $row->date; ?></pubDate>
<link>http://cmstutorials.org/view_tutorial.php?tutorial_id=<?php echo $row->tutorial_id; ?></link>
</item>
<?php
}
?>
</channel>
</rss>
I checked the query by executing it in phpmyadmin and it works, doesn't give any error. When I delete the header content type and the rss tag it will print out each line from the query but the feed won't display anything
this is the link of the feed http://cmstutorials.org/rss (or http://cmstutorials.org/rss.php)
Funnily enough, IE8 is the one to give a detailed error message where Firefox says nothing for a change. It says "this feed cannot be displayed due to errors" and points to Line 229, column 32.
<description>We
this is 99.9999% an encoding problem. (The validator complains about a non-UTF-8 character.) Most likely, you have your database contents stored in a character set different from utf-8.
You will get more detailed info running the feed through a validator.
Your file is valid UTF-8, but is not valid XML. I think that you'll probably need to pass all your data through the htmlentities function.
<title><?php echo htmlentities($row->title,ENT_QUOTES,"utf-8"); ?></title>
<author><?php echo htmlentities($row->username,ENT_QUOTES,"utf-8"); ?></author>
<description><?php echo htmlentities($row->description,ENT_QUOTES,"utf-8"); ?></description>
<pubDate><?php echo htmlentities($row->date,ENT_QUOTES,"utf-8"); ?></pubDate>
If that doesn't work, try changing the "utf-8" to other encodings like "cp1252" or "iso-8859-1".
精彩评论