/ Published in: PHP
Generating RSS Feeds using SimpleXML in PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// create simplexml object $xml = new SimpleXMLElement('<rss version="2.0" encoding="utf-8"></rss>'); // static channel data $xml->addChild('channel'); $xml->channel->addChild('title', 'FRD Videos RSS Feeds'); $xml->channel->addChild('link', 'http://www.ste.com/feeds/'); $xml->channel->addChild('description', 'Latest Videos at FRD'); $xml->channel->addChild('language', 'en-us'); $xml->channel->addChild('generator', 'PHP SimpleXML'); $xml->channel->addChild('docs', 'http://www.site.com/videos.xml'); // static channel data ( we get more from db in section below) // query database for article data ... // query database for article data // Here we get more date from database for our xml // add item element for each article $item = $xml->channel->addChild('item'); $item->addChild('link', 'http://www.site.com/'.$row['id'].'.html'); } // Here we get more date from database for our xml // save the xml to a file if($xml->asXML('videos.xml')) { }