If there is a problem reading the cache file (and you are not To see the actual error message from the server, you will need to change this line in the class file: $fp = 'r') or die("RSSParser: Could not open $file for input") Not keeping files in place for sufficient time then you will need toĬreate your own webserver-writable directory and change the If the /tmp/ directory does not exist, is not writable or is Relevant data can be stored on the server. Have to be fetched again every time the page is loaded, but rather the The /tmp/ directory and that those files will remain there, This code assumes that the script has permission to create files in RSSParser: Could not open $file for inputįopen to fetch the RSS feed, so the following is no longer Purposes only and care should be taken when using or modifying it forĪny other purpose. Please Note: this code is provided for explanatory Items so you may need to customise what is displayed. Not all RSS/Atom feeds will contain the same At the bottom it displays also theĬopyright information. The image associated with the feed (as a link) followed by the feed If($feed_contents = http_get_contents( $BLOGURL)) \n" Īs you can see from the code comments, this snippet displays first The array returned by getRawOutput() and adding some simple The parameters at the top define the feed source, how many items toĭisplay and where and for how long to keep a local cached version of theĪfter that it's just a matter of extracting the relevant data from = 'Copyright (C) 2009 mywebsite.Again, this is just an example of what you can do using our PHPĬlasses (there's also code for an Atom Feed Or die ( 'Could not select database' ) $query = "SELECT * FROM mytable ORDER BY date DESC" $result = mysql_query ( $query ) or die ( "Could not execute query" ) while ( $row = mysql_fetch_array ( $result ) ) $rssfeed. Or die ( 'Could not connect to database' ) mysql_select_db (DB_NAME ) $connection = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD ) We are going to assume that our MySQL table (“mytable”) has columns called title, description, link and date which hold the relevant data: I’m not going to explain this part in too much details as it’s not point of this tutorial and you may do this differently. Next, we need to extract our data by looping through our MySQL database to create the tags. The first thing we are going to do is tell PHP what type of data we would like to output (I am going to break each section of the script down, but I will include it in full at the end): php extension, but we will tidy this up later in the tutorial. This means that the URL for our feed will end with the. What we are going to do is create this standard XML data dynamically using PHP. Creating the feedĪs we know, RSS is made up of standardised XML tags which you would normally find in a flat XML file. Take a look at the RSS Wikipedia page for a full history of RSS and it’s various different versions. My RSS feed This is an example RSS feed en-us Copyright (C) 2009 My News Story 3 This is example news item Mon, 09:27:16 0000 My News Story 2 This is example news item Wed, 12:00:00 0000 My News Story 1 This is example news item Wed, 15:57:20 0000 Here is an example of a basic RSS document, we will be generating something similar using PHP later in this tutorial: The RSS format is based on XML that is built using standardised tags. The RSS Feed (as it is commonly known) can then be read by the users feed reading software or by another website which wishes to ‘syndicate’ the content of that feed. RSS, in its current form, stands for Really Simple Syndication and is a family of web formats to publish frequently updated content. Hopefully this tutorial will help you to achieve this. Perhaps you have just won a new client who’s current site has an old bespoke CMS which they like and want to keep, but you want to be able to publish their updated content via RSS. Sometimes, however, it might be necessary for you to create a RSS feed yourself. If you have a blog or use any form of CMS, that software will most likely handle the creation of your RSS feed for you. It’s not a new technology and it’s probably something that you use on a daily basis. Having an RSS feed on your website is a great way of sharing your content with the rest of the Internet. Create an RSS feed with PHP Originally posted on 18th March 2009 by Ian Harris
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |