To some folks rss is this hot new technology that is changing our lives in technology. The truth is rss is a specific formated text file that people finally have standarized on. It’s the standarization that changes people lives, not neccessary the technology. Anyway, a while back I wanted to rss feed our knowledgebase. The knowledgebase articles are stored in a mysql database. I played around with using PEAR::PACKAGE::XML to do the job but found it to be a bit overkill. So I wrote my own xml builder – source code is below or you can download the php rss feed mysql database code. What is nice, is that you can RSS feed any database.
// prepare HTML text for use as UTF-8 character data in XML
function cleanText($intext) {
return utf8_encode(
htmlspecialchars(
stripslashes($intext)));
}
// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=utf-8");
// retrieve database records
$db = mysql_connect("YourMySQLSERVER", "YOURUSERNAME", "YOURPASSWORD");
if (!$db)
{
error_log("Error: Could not connect to database in rss.php.");
exit;
}
// store items from the database in the $result1 array
mysql_select_db("knowledgebase");
$query1 = "SELECT faqarticles.question, faqarticles.content, SUBSTRING(content,1,600) as mycontent,
faqarticles.cat, faqarticles.id, faqarticles.date FROM faqarticles WHERE
faqarticles.approved != '1'
ORDER BY faqarticles.date DESC";
$result1 = mysql_query($query1);
$phpversion = phpversion();
// display RSS 2.0 channel information
ECHO <<
END;
// loop through the array pulling database fields for each item
for ($i = 0; $i < mysql_num_rows($result1); $i++) {
@$row = mysql_fetch_array($result1);
$title = cleanText($row["question"]);
$link = "http://www.YourSite.com/kb/index.php?article=".$row["id"];
$description = $row["mycontent"];
//Replace Ugly HTML that got into the Knowledgebase with nothing
$desc_replace = array("
", "
", );
$desc_replace_with = array("", "", "");
$desc_temp = str_replace($desc_replace, $desc_replace_with, $description);
//Now clean the HTML
$mydescription = cleanText($desc_temp);
$pubDate = $row["date"];
// display an item } ECHO << ?>
ECHO <<
END;
END;
Wish that code was still up.
i am working with news site. i want rss feed that have the latest vedio news. how to store the rss feed my control pannel please tell me
This code looks very useful, I use my blog test it. Nice features
Hello there folks,
I am a website specialist attempting to expand my perspectives by learning PHP and mySQL.I have been learning mySQL for a couple of months now by taking after instructional exercises and so on and have a significant decent comprehension of the arrangement now. I have onto adding a mySQL database to my site utilizing PHP (I am still at the beginning phases of learning PHP).
really such an impressive and knowledgeable post, RSS solves a problem for people who regularly use the web. It allows you to easily stay informed by retrieving the latest content from the sites you are interested in. You save time by not needing to visit each site individually. and I love to use the RSS but recently I have to face some difficulties in my web project but after your post it really the reason for my solution.
Thanks!
What is nice, is that you can RSS feed any database.
This is such a tremendous and useful post. I appreciate this content and also the writer of this article. Thanks for sharing in public. Keep improve.