Home arrow PHP arrow Page 5 - Rockin’ RSS with PHP on your HTML

Adding content - PHP

An RSS feed lets webmasters tease visitors into returning to their websites again and again to check out new content. Danny Wall explains how to set up this simple, automated, spamless way of getting Web surfers to come back for more.

TABLE OF CONTENTS:
  1. Rockin’ RSS with PHP on your HTML
  2. An idea that's catching on
  3. How--and why--to get started
  4. Starting with the header
  5. Adding content
  6. Tease the reader
By: Danny Wall
Rating: starstarstarstarstar / 42
November 23, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

At this point, you now need to begin adding the “item” level information; which is simply the content that has been added to your site. Before we get started on this, there are some things you need to know.

Generally, an RSS feed contains not only the most recently added content to your site, but quite a bit of “back” content as well. This is to allow any new users to not only see the most recent additions, but also see what has been done before they picked up your feed. This way, they'll easily be able to look at that as well.

It’s a good thing for the new user, and for you, as often a person that picks up a new feed will spend some time checking out a lot of the “past” content and catching up on what you’ve got going.

That means we need to do two things.

First, you need to database your new content. In otherwords, you should be adding new content to your database, and your website should be pulling that new content out of the database. This will allow you to utilize PHP with maximum benefit and speed to build the RSS file.

$db = mysql_connect("localhost","your_db_uid","your_db_pw");
mysql_select_db("db_name",$db);
$content_sql = "select * from content where page='index' order by id desc";

Obviously in the above line, you are seeing how I do it. Your query may be different depending on how you are databasing your content.

$content_result = mysql_query($content_sql);

So far, we’re still in the “basic” neck of the woods.  In fact, all we need to do now is pull the content out of your site and put it into the RSS file.

while ($content_rec = mysql_fetch_row($content_result)) {
    fwrite ($pd, "<item>");

    $headline = $content_rec[0];
    $content_1 = substr($content_rec[1], 0, 250);
    $content = strip_tags($content_1);
    if (strlen($content_rec[1]) > 250) {
        $content = $content . "....";
    }
    fwrite ($fp, "<title>$headline</title>");
    fwrite ($fp, "<description>$content</description>");
    $item_link = "http://www.wolfdatasystems.com/index.php?d=$content_rec[3]";
    fwrite ($fp, "<link>$item_link</link>");

    fwrite ($fp, "</item>");
}



 
 
>>> More PHP Articles          >>> More By Danny Wall
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap

Dev Shed Tutorial Topics: