nicky666 Posted January 28, 2014 Share Posted January 28, 2014 Hi i'm trying to create a rss page, the problem I have is that the data is not showing. If I check the page source the data is there but it's not showing up and I can't seem to figure out why or how to fix it. <?php ini_set('display_errors', 1); header("Content-type: text/xml"); include("includes/database.php"); global $NEWS; $str = '<?xml version="1.0" encoding="UTF-8"?>'; $str.= '<rss version="2.0">'; $str.='<channel>'; $sql = "SELECT * FROM news"; $result = mysql_query($sql) or die ($sql."".mysql_error()); while($row = mysql_fetch_object($result)){ $str.= '<item>'; $str.= '<title>'.$row->title.'</title>'; $str.= '<description>'.$row->content. '</description>'; $str.= '</item>'; } $str .='</channel>'; $str .='</rss>'; echo $str; Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 28, 2014 Share Posted January 28, 2014 Is that the entire code? If so, you're missing the closing PHP tag. //... echo $str; ?> If that doesn't work, have you tried validating the feed? http://validator.w3.org/feed/ Quote Link to comment Share on other sites More sharing options...
nicky666 Posted January 28, 2014 Author Share Posted January 28, 2014 I validated the feed and I got this This feed does not validate. line 1, column 113: Undefined description element: p [help] ... title>xzfbcbcxv 123</title><description><p>Mr. Kim Keats-Martínez, Execu ... ^ line 1, column 116: XML parsing error: <unknown>:1:402: not well-formed (invalid token) [help] ... le>xzfbcbcxv 123</title><description><p>Mr. Kim Keats-Martínez, Executiv ... I'm not sure how I'm going to fix this as the cms I'm using puts the <p> tag automatically Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted January 28, 2014 Solution Share Posted January 28, 2014 (edited) You need to contain your HTML within CDATA. Otherwise the XML parser thinks it is part of your XML structure and so you'll get validation errors. $str.= '<description><![CDATA['.$row->content. ']]></description>'; Alternatively convert the html to htmlentities Edited January 28, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
nicky666 Posted January 28, 2014 Author Share Posted January 28, 2014 Thank you so much Ch0cu3r that worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.