$sth = $conn->prepare("SELECT * FROM `products` ORDER BY id desc") SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION) Next we create a feed.php page to create the RSS feed for the website. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `created_at` timestamp NULL DEFAULT NULL, `status` tinyint(4) NOT NULL DEFAULT '1', `description` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL, `link` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, So we are starting with a database that we want to store all the entries for our website. tag contains a, , tag to describe your content in the site. In side you can see that tag is repeating, that will be the main items. The main RSS content comes under the tag. It starts with the usual RSS encoding tag, and then it indicates the version of RSS in the next line with tag. This is a basic RSS structure that is essential for any website. You can see the below file for basic sample RSS feed In this tutorial I am demonstrating a simpel RSS feed script, that let you to create a dynmaic RSS feed for your beautiful website. If they have RSS feeds in their website you can just subscribe it in a RSS reader, so RSS reader tool will capture the latest entries for you and you can read it later. If you like a website that producing good content, you need to check the website every day to read latest updates. In the code above, I have used the file_get_contents function, which returns false on failure.Short for Really Simple Syndication or Rich Site Summary, it’s the way to communicate to your website. If this condition is true, the feed’s actual XML content is fetched by using one of the PHP functions for getting the source code of an URL. Notice that RSS feed frequency is stored in minutes, so it has to be multiplied by 60. A feed should be fetched if the number of seconds elapsed between the current time and the last access time is larger than the feed’s access frequency. After that, we loop through the array and check which feeds should be fetched. I have used the basic PHP functions for connecting to the database, but feel free to replace them with your own database manipulation class. Mysql_query("UPDATE feed SET last_access='".time()."' WHERE id='".$feed."'") įirst, the list of RSS feeds is fetched from the database and stored into an array. $insert_q = "INSERT IGNORE INTO article (title,content,url,pub_date,insert_date) VALUES ( $content = file_get_contents($row) // this could be done with cURL Although this can be done on the fly, it would be quite slow, so we would rather use the database table to store and fetch data: The main task of an RSS aggregator is to combine data from multiple feeds and display them as one list. Unlike the description tag, content:encoded can contain HTML tags, which is shown in the example above. The purpose of this tag is to overcome limitations of the description tag, which allows only plain text. However, there is one more tag that has become often used nowadays: content:encoded. There are many other tags that can be used in RSS feeds, but they are optional and rarely used. As well as the other dates and times in RSS, pubDate conforms to the Date and Time Specification of RFC 822. Title and description represent the title and description of the content, link is the full URL to that content, guid is a unique identification of the particular article (usually the URL) and pubDate is the time when content is published. Items usually have the following data: title, description, link, guid and pubDate. After that, there is some data describing the feed itself, such as the title and the description of the RSS feed. At the beginning of the document, the encoding and RSS version are defined.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |