Web server on xp - WRITE YOUR OWN BLOG ENGINE if (!$fw) {
WRITE YOUR OWN BLOG ENGINE if (!$fw) { $message = “Could not write to the file $filename”; } else { $message = “RSS file updated.”; } // close file fclose($fh); } else { $message = “Could not open file $filename”; } return $message; } Your code will be calling the function from more than one place, so the ideal place to add it is in the functions.php include you made earlier. Make sure that the makerssfeed function is placed before the closing ?> delimiter. I will now step through the function. It is really just a simplified version of your blog home- page: It grabs the ten most recent blog entries from the database and writes them to a file. The main differences will be the RSS file syntax (which is similar to but different from HTML) and some new functions for file handling, which is what we kick off with: function makerssfeed() { // set file to write $filename = $_SERVER[”DOCUMENT_ROOT”] . “/index.xml”; // open file $fh = @fopen($filename, “w”); if($fh) { Here, the full server path of the RSS file is written to the $filename variable. Next, the fopen function is used to open the file for writing (that s what the w means). As mentioned earlier in the chapter, the @ before the function call prevents any ugly errors being written to the screen. I m writing the fopen function to the $fh variable. If the fopen function failed (perhaps the index.xml file doesn t exist or it is read-only), the value of $fh is false, and there s no point continuing with the function. $rssfile = “
http://your-domain-name.com