PHP Cookbook by David Sklar & Adam Trachtenberg
Author:David Sklar & Adam Trachtenberg
Language: eng
Format: epub
ISBN: 9781449363758
Publisher: O’Reilly Media, Inc.
Published: 2014-10-26T16:00:00+00:00
Figure 12-2. php.announce RSS channel information
See Also
The MagpieRSS homepage; more information on RSS at Wikipedia.
Writing RSS Feeds
Problem
You want to generate RSS feeds from your data. This will allow you to syndicate your content.
Solution
Use this class:
class rss2 extends DOMDocument { private $channel; public function __construct($title, $link, $description) { parent::__construct(); $this->formatOutput = true; $root = $this->appendChild($this->createElement('rss')); $root->setAttribute('version', '2.0'); $channel= $root->appendChild($this->createElement('channel')); $channel->appendChild($this->createElement('title', $title)); $channel->appendChild($this->createElement('link', $link)); $channel->appendChild($this->createElement('description', $description)); $this->channel = $channel; } public function addItem($title, $link, $description) { $item = $this->createElement('item'); $item->appendChild($this->createElement('title', $title)); $item->appendChild($this->createElement('link', $link)); $item->appendChild($this->createElement('description', $description)); $this->channel->appendChild($item); } } $rss = new rss2('Channel Title', 'http://www.example.org', 'Channel Description'); $rss->addItem('Item 1', 'http://www.example.org/item1', 'Item 1 Description'); $rss->addItem('Item 2', 'http://www.example.org/item2', 'Item 2 Description'); print $rss->saveXML();
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9373)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9343)
The Mikado Method by Ola Ellnestam Daniel Brolund(9307)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7852)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7402)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7324)
Grails in Action by Glen Smith Peter Ledbrook(7296)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7117)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5957)
Kotlin in Action by Dmitry Jemerov(4638)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3887)
Functional Programming in JavaScript by Mantyla Dan(3723)
Learning Java by Patrick Niemeyer & Daniel Leuck(2872)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2839)
Mastering Python for Finance by Weiming James Ma;(2839)
Windows APT Warfare by Sheng-Hao Ma(2615)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2602)
Mastering Java 9 by Dr. Edward Lavieri(2573)
Architecting Modern Java EE Applications: Designing lightweight, business-oriented enterprise applications in the age of cloud, containers, and Java EE 8 by Daschner Sebastian(2559)