wfareed Posted August 21, 2012 Share Posted August 21, 2012 i created this file to produce xml file to use is as rss feed , the file i created is here : <?php //output page as xml header("Content-type: text/xml"); //connect to mysql databse mysql_connect("localhost","root","") or die(mysql_error()); //select database to get data from mysql_select_db("blog") or die(mysql_error()); //start our query $sql = "SELECT * FROM articles ORDER BY id DESC"; //get the results $res = mysql_query($sql) or die(mysql_error()); //start XML $xml_output = "<?xml version='1.0' encoding='UTF-8'?>\n<section>\n"; for($x = 0 ; $x < mysql_num_rows($res) ; $x++){ $row = mysql_fetch_assoc($res); $xml_output .= "\t<rec>\n"; $xml_output .= "\t\t<idx>" . $row['id'] . "</idx>\n"; $xml_output .= "\t\t<article>" . $row['article_name'] . "</article>\n"; $xml_output .= "\t\t<author>" . $row['author'] . "</author>\n"; $xml_output .= "\t\t<contents>" . $row['article'] . "</contents>\n"; $xml_output .= "\t</rec>\n"; } $xml_output .= "</section>"; $foodata = $xml_output; $fp = fopen("rss.xml", "w"); fwrite($fp, $foodata); fclose($fp); ?> the php is producing this xml file with no errors : <?xml version='1.0' encoding='UTF-8'?> <section> <rec> <idx>3</idx> <article>testing</article> <author>wfareed</author> <contents>anything anything</contents> </rec> <rec> <idx>2</idx> <article>Then what ?</article> <author>damntraitors</author> <contents><p style="font-size:20px;"> Now the elections is over , And what happened had happened!. </p></contents> </rec> <rec> <idx>1</idx> <article>?????? ?</article> <author>damntraitors</author> <contents><p style="font-size:20px;">????? ?? ?????????? ???? ???? ? ???? ??? ???</p> </contents> </rec> </section> the issue is , when i try to read this xml file from any rss reader like google reader or rssreader or outlook rss reader i have an error saying that the file can not be processed as a valid RSS source !!!! any idea please ? Link to comment https://forums.phpfreaks.com/topic/267379-error-reading-php-created-xml-file-as-rss-feed/ Share on other sites More sharing options...
MMDE Posted August 21, 2012 Share Posted August 21, 2012 Maybe you need to look into how to properly format the rss... I know this works, at least it used to work, with firefox: <?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0"> <channel> <title></title> <link></link> <description></description> <item> <title></title> <link></link> <description></description> </item> <item> <title></title> <link></link> <description></description> </item> <item> <title></title> <link></link> <description></description> </item> </channel> </rss> It seems you are missing the rss tag. Link to comment https://forums.phpfreaks.com/topic/267379-error-reading-php-created-xml-file-as-rss-feed/#findComment-1371149 Share on other sites More sharing options...
wfareed Posted August 21, 2012 Author Share Posted August 21, 2012 Thanks for your help , Got some issues with this one too but it is better than the older version , Thanks man Link to comment https://forums.phpfreaks.com/topic/267379-error-reading-php-created-xml-file-as-rss-feed/#findComment-1371176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.