1 / 12

Creating and Reading an RSS Feed using PHP

Creating and Reading an RSS Feed using PHP. Christine Marquardt IMD410 | Project 2. CREATING RSS with PHP. Background: RSS or Really Simple Syndication is a simple XML markup used to standardize content distribution and syndication.

bevis
Download Presentation

Creating and Reading an RSS Feed using PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating and Reading an RSS Feed using PHP Christine Marquardt IMD410 | Project 2

  2. CREATING RSS with PHP • Background: RSS or Really Simple Syndication is a simple XML markup used to standardize content distribution and syndication. • Purpose of RSS: Syndicating your content through various feed directories and search engines widen your distribution. It also provides your content consumers with an easy way to keep up with updates and new content. Source: http://www.tutcity.com/view/creating-an-rss-feed-with-php-and-mysql.20475.html

  3. 1. Set up Table Information Create Table - basic required information for the feed are title, description, link, and URL Two database tables, the first is called webref_rss_details, which contains the details for the feed and the second is called webref_rss_items, which contains all of the items Source: http://www.tutcity.com/view/creating-an-rss-feed-with-php-and-mysql.20475.html and http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/

  4. 1. Set up Table Information 10 columns 'webref_rss_details' ( 'id' int(11) NOT NULL auto_increment, 'title' text NOT NULL, 'description' mediumtext NOT NULL, 'link' text, 'language' text, 'image_title' text, 'image_url' text, 'image_link' text, 'image_width' text, 'image_height' text, PRIMARY KEY ('id')) ENGINE=MyISAM DEFAULT CHARSET=utf8; Source: http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/

  5. 1. Set up Table Information 4 columns; link goes to the original info from RSS 'webref_rss_items' ( 'id' int(11) NOT NULL auto_increment, 'title' text NOT NULL, 'description' mediumtext NOT NULL, 'link' text, PRIMARY KEY ('id')) ENGINE=MyISAM DEFAULT CHARSET=utf8; Source: http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/

  6. 2. PHP and RSS Index.php – GetFeed method returns the RSS <? header("Content-Type: application/xml; charset=ISO-8859-1"); include("classes/RSS.class.php"); $rss = new RSS(); echo $rss->GetFeed(); ?> Source: http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/

  7. 2. PHP: Making Database Connection mysql_connect.php – connecting to the database <? DEFINE ('DB_USER', 'your_username'); DEFINE ('DB_PASSWORD', 'your_password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'your_databasename'); // Make the connnection and then select the database. $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() ); mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() ); ?> Source: http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/

  8. 4. RSS Methods SEE REFERENCE:http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/ <? class RSS { public function RSS() { require_once ('pathto.../mysql_connect.php'); } public function GetFeed() { return $this->getDetails() . $this->getItems(); } private function dbConnect() { DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)); } private function getDetails() { $detailsTable = "webref_rss_details"; $this->dbConnect($detailsTable); $query = "SELECT * FROM ". $detailsTable; $result = mysql_db_query (DB_NAME, $query, LINK);……….

  9. READING RSS FEED WITH PHP File Structure: • index.php • css (folder) – default.css • js (folder) – jquery-1.2.6.pack.js; myScript.js • includes (folder) – functions.php Source: http://net.tutsplus.com/videos/screencasts/how-to-read-an-rss-feed-with-php-screencast/

  10. READING RSS FEED WITH PHP functions.php <?php function getFeed($feed_url) { $content = file_get_contents($feed_url); $x = new SimpleXmlElement($content); echo "<ul>"; foreach($x->channel->item as $entry) { echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>"; } echo "</ul>"; } ?> Source: http://net.tutsplus.com/videos/screencasts/how-to-read-an-rss-feed-with-php-screencast/

  11. READING RSS FEED WITH PHP index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <link rel="stylesheet" href="css/default.css" /> <script src="js/jquery-1.2.6.pack.js" type="text/javascript"></script> <script src="js/myScript.js" type="text/javascript"></script> </head> <body> <?php require_once "includes/functions.php"; ?> <div id="wrap">\ <ul id="nav"> <li><a href="#content_1" class="selected">NETTUTS</a></li> <li><a href="#content_2">ThemeForest</a></li> <li><a href="#content_3">Screencasts</a></li> </ul> <div id="mainContent"> <div id="content_1"> <?php getFeed("http://feedproxy.google.com/nettuts"); ?> </div><!--end content 1--> <div id="content_2"> <?php getFeed("http://feedproxy.google.com/themeforest"); ?> </div><!--end content 2--> <div id="content_3"> <?php getFeed("http://feeds.feedburner.com/NETTUTSVideos"); ?> </div><!--end content 3--> </div><!--end main content --></div><!--end wrap--> </body></html> Source: http://net.tutsplus.com/videos/screencasts/how-to-read-an-rss-feed-with-php-screencast/

  12. REFERENCES & RESOURCES • Hadlock, Kris. "Creating a Custom RSS Feed with PHP and MySQL." webreference. 02 24 2009. Web. 5 Feb 2010. <http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/>. • "PHP - Creating An RSS Feed with PHP and MySQL." HigherPass. Web. 5 Feb 2010. <http://www.tutcity.com/view/creating-an-rss-feed-with-php-and-mysql.20475.html>. • Way, Jeffrey. "How to Read an RSS Feed with PHP." nettuts. Web. 4 Feb 2010. <http://net.tutsplus.com/videos/screencasts/how-to-read-an-rss-feed-with-php-screencast/>. • RESOURCES: net.tutsplus.com, tutcity.com, http://www.developertutorials.com/blog/php/rss-feeds-in-php-3-simple-steps-to-php-rss-generation-121/, http://searchenginewatch.com/2175271

More Related