tags:

views:

46

answers:

2

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&lt;/link&gt;
        <?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=&lt;?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)

+4  A: 

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.

Pekka
oh I never thought looking in IE, but what you are saying is 100% possible as I have encoding problems -> http://cmstutorials.org/ check the description, there are little squares. I set the the database to utf8-unicode. The content that I add to the database is from rss feeds
krike
I tried reincoding the incoming rss feeds to UTF8 but still there seems to be a few problems. I will use a few filters to change the special quotes into normal utf8 standard quotes. Or something like that
krike
Hey that rss validator just saved my life. So thanks and +1!! I always use the html and css validators but never realised there was one for rss.
Iznogood
+1  A: 

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".

Dumb Guy
Nope, it's not valid UTF-8, at least one character is broken. Plus, never ever use `htmlentities` on XML output. Use normal UTF-8 characters or wrap the data in CDATA tags.
Pekka
thank you for the tips guys. I'm about to convert my current site into the codeigniter framework so all of this should be fixed. I used the code above provided even if Pekka says it's not recommended as it a preliminary fix
krike