pwnuspoints Posted April 30, 2009 Share Posted April 30, 2009 Hey phpfreaks, I have been in the process of making an RSS feed for a day now and I'm finally making some progress. As it turns out my troubles have something to do with removing the html tags from my description. I've been working with tutorial after tutorial which all claim to work. However, when I modify any tutorial code for myself the feed goes blank. I started from scratch too many times to mention. So finally I decided to give up on tutorials and try coding for myself. The code below is what I've come up with. If you ignore the fact that It has no description, everything works fine. <?xml version="1.0"?> <rss version="2.0"> <channel> <title>Title</title> <link>http://www.url.com/</link> <description>RSS feed.</description> <language>en-us</language> <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate> <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate> <webMaster>[email protected]</webMaster> <?php include '../library/config.php'; include '../library/opendb.php'; $result = mysql_query("SELECT * FROM table ORDER BY sn DESC LIMIT 0, 15"); while($r=mysql_fetch_array($result)) { $title=$r["title"]; $timestamp=$r["timestamp"]; $link=$r["link"]; $body=$r["body"]; echo " <item> <title>$title</title> <link>$link</link> <pubDate>$timestamp</pubDate> </item>"; } include '../library/closedb.php'; ?> </channel> </rss> Whever I add a description to the above code -- the feed goes blank. My "description" comes from the "body" column of my table. The body column stores rich text as html. I need to strip the html from '$body' before using it in the xml item description. However, every attempt I've made at stripping the html makes the whole thing stop working. Here's what my recent attempt looks like: <?xml version="1.0"?> <rss version="2.0"> <channel> <title>Title</title> <link>http://www.url.com/</link> <description>RSS feed.</description> <language>en-us</language> <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate> <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate> <webMaster>[email protected]</webMaster> <?php include '../library/config.php'; include '../library/opendb.php'; $result = mysql_query("SELECT * FROM table ORDER BY sn DESC LIMIT 0, 15"); while($r=mysql_fetch_array($result)) { $title=$r["title"]; $timestamp=$r["timestamp"]; $link=$r["link"]; $body=$r["body"]; $description=strip_tags($body); echo " <item> <title>$title</title> <link>$link</link> <description>$description</description <pubDate>$timestamp</pubDate> </item>"; } include '../library/closedb.php'; ?> </channel> </rss> I have two seperate questions: 1) What can am I doing wrong? 2) Is there anything wrong with the way I've decided to code this RSS feed? Would you safely use this code? If not, why? Any help is sincerely appriciated, thank you! -B. Link to comment https://forums.phpfreaks.com/topic/156310-solved-prepare-string-for-rss/ Share on other sites More sharing options...
mikesta707 Posted April 30, 2009 Share Posted April 30, 2009 have you tried the htmlentities() function? Link to comment https://forums.phpfreaks.com/topic/156310-solved-prepare-string-for-rss/#findComment-822944 Share on other sites More sharing options...
pwnuspoints Posted April 30, 2009 Author Share Posted April 30, 2009 have you tried the htmlentities() function? I just tried htmlentities and it worked! Well that was easier than I was expecting. Thanks mikesta707! Just in case, here's the code: while($r=mysql_fetch_array($result)) { $title=$r["title"]; $timestamp=$r["timestamp"]; $link=$r["link"]; $body=$r["body"]; $description=htmlentities($body); echo " <item> <title>$title</title> <link>$link</link> <description>$description</description> <pubDate>$timestamp</pubDate> </item>"; } Link to comment https://forums.phpfreaks.com/topic/156310-solved-prepare-string-for-rss/#findComment-822959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.