Jump to content

Recommended Posts

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 ?

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. :P

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.