...

View Full Version : how PHP print out RSS?



terter2000
01-13-2010, 02:19 PM
How PHP able to print out a rss html page like this:
feed://feeds.wired.com/wired/index

this is my code below , asking php to print out a xml data , how can it into a rss like the above one?


echo "<?xml version=\"1.0\"?>\n";
echo "<data>\n";

while($line = mysql_fetch_assoc($results)) {
echo "<sndata sn=\"" . $line["serial_no"]."\">\n";
echo "<companyname>" . $line["company_name"] . "</companyname>\n";
echo "<numberid>" . $line["number_id"] . "</numberid>\n";

}

abduraooft
01-13-2010, 03:03 PM
Take a look at http://www.supadupawebdesign.co.uk/tutorials/PHP-1/Easy-Dynamic-RSS-Feed-in-PHPMySQL-11 (of course, it gets data from mysql DB, but you may easily modify it)

JAY6390
01-13-2010, 03:48 PM
Firstly use single quotes to write your xml data structure and also sprintf your values into a template for the looping process. It makes your code so much cleaner to read. Example


<?php
$output = '<?xml version="1.0"?>
<data>';

$datatemplate = '
<sndata sn="%s">
<companyname>%s</companyname>
<numberid>%s</numberid>
</sndata>';

while($line = mysql_fetch_assoc($results)) {
$output .= sprintf($datatemplate, $line['serial_no'], $line['company_name'], $line['number_id']);
}

$output .= '
</data>';

header('Content-Type: text/xml');
echo $output;Note that I also used the text/xml header to signify to your browser that this is an xml document

terter2000
01-13-2010, 05:28 PM
hey thanks experts , it helps +rep and everything !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum