Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - RSS builder
    text
    copied!<p>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.</p> <p>Here is the example when saving (I read before save to append old RSS line of course).</p> <pre><code>function SaveXml() { if (!is_file($this-&gt;getFileName())) { //Création du fichier $file_handler = fopen($this-&gt;getFileName(),"w"); fwrite($file_handler,""); fclose($file_handler); }//Fin du if //Header xml version="1.0" encoding="utf-8" $strFileData = '&lt;?xml version="1.0" encoding="iso-8859-1" ?&gt;&lt;rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"&gt;&lt;channel&gt;&lt;title&gt;'.$this-&gt;getProjectName().'&lt;/title&gt;&lt;link&gt;http://www.mywebsite.com&lt;/link&gt;&lt;description&gt;My description&lt;/description&gt;&lt;lastBuildDate&gt;' . date("r"). '&lt;/lastBuildDate&gt;'; //Data reset($this-&gt;arrData); foreach($this-&gt;arrData as $i =&gt; $value) { $strFileData .= '&lt;item&gt;'; $strFileData .= '&lt;title&gt;'. $this-&gt;GetNews($i,0) . '&lt;/title&gt;'; $strFileData .= '&lt;pubDate&gt;'. $this-&gt;GetNews($i,1) . '&lt;/pubDate&gt;'; $strFileData .= '&lt;dc:creator&gt;'. $this-&gt;GetNews($i,2) . '&lt;/dc:creator&gt;'; $strFileData .= '&lt;description&gt;&lt;![CDATA['. $this-&gt;GetNews($i,3) . ']]&gt; &lt;/description&gt;'; $strFileData .= '&lt;link&gt;&lt;![CDATA['. $this-&gt;GetNews($i,4) . ']]&gt;&lt;/link&gt;'; $strFileData .= '&lt;guid&gt;'. $this-&gt;GetNews($i,4) . '&lt;/guid&gt;'; //$strFileData .= '&lt;category&gt;'. $this-&gt;GetNews($i,5) . '&lt;/category&gt;'; $strFileData .= '&lt;category&gt;Mycategory&lt;/category&gt;'; $strFileData .= '&lt;/item&gt;'; }//Fin du for i $strFileData .= '&lt;/channel&gt;&lt;/rss&gt;'; if (file_exists($this-&gt;getFileName()))//Détruit le fichier unlink($this-&gt;getFileName()); $file_handler = fopen($this-&gt;getFileName(),"w"); fwrite($file_handler,$strFileData); fclose($file_handler); }//Fin de SaveXml </code></pre> <p>My question is : how do you create and fill up your RSS in PHP?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload