I have a old website that generate its own RSS everytime a new post is created. Everything worked when I was on a server with PHP 4 but now that the host change to PHP 5, I always have a ‘bad formed XML’. I was using xml_parser_create() and xml_parse(…) and fwrite(..) to save everything.
Here is the example when saving (I read before save to append old RSS line of course).
function SaveXml() { if (!is_file($this->getFileName())) { //Création du fichier $file_handler = fopen($this->getFileName(),'w'); fwrite($file_handler,''); fclose($file_handler); }//Fin du if //Header xml version='1.0' encoding='utf-8' $strFileData = '<?xml version='1.0' encoding='iso-8859-1' ?><rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'><channel><title>'.$this->getProjectName().'</title><link>http://www.mywebsite.com</link><description>My description</description><lastBuildDate>' . date('r'). '</lastBuildDate>'; //Data reset($this->arrData); foreach($this->arrData as $i => $value) { $strFileData .= '<item>'; $strFileData .= '<title>'. $this->GetNews($i,0) . '</title>'; $strFileData .= '<pubDate>'. $this->GetNews($i,1) . '</pubDate>'; $strFileData .= '<dc:creator>'. $this->GetNews($i,2) . '</dc:creator>'; $strFileData .= '<description><![CDATA['. $this->GetNews($i,3) . ']]> </description>'; $strFileData .= '<link><![CDATA['. $this->GetNews($i,4) . ']]></link>'; $strFileData .= '<guid>'. $this->GetNews($i,4) . '</guid>'; //$strFileData .= '<category>'. $this->GetNews($i,5) . '</category>'; $strFileData .= '<category>Mycategory</category>'; $strFileData .= '</item>'; }//Fin du for i $strFileData .= '</channel></rss>'; if (file_exists($this->getFileName()))//Détruit le fichier unlink($this->getFileName()); $file_handler = fopen($this->getFileName(),'w'); fwrite($file_handler,$strFileData); fclose($file_handler); }//Fin de SaveXml
My question is : how do you create and fill up your RSS in PHP?
At swcombine.com we use Feedcreator. Use that one and your problem will be gone. 🙂
Here is the PHP code to use it once installed:
Quite KISS. 🙂