I have a page called rss.php that contains PHP SQL and XML which dynamically, and might I add PERFECTLY, produces the XML needed for the rss feed for my podcast. Only problem is, its a PHP file. I need to get the stuff this page spits out in to a file named rss.xml for iTunes to accept it. I came across this little bit of code in another thread:
echo $xml->asXML('filename.xml');
and this on http://php.tonnikala.org:
<?php
$string = <<<XML
<a>
<b>
<c>text</c>
<c>stuff</c>
</b>
<d>
<c>code</c>
</d>
</a>
XML;
$xml = new SimpleXMLElement($string);
echo $xml->asXML(); // <?xml ... <a><b><c>text</c><c>stuff</c> ...
?>
Problem is when I wrap my XML in this code, the browser gives me an error and it doesn’t load. This may be because my XML isn’t just XML, it’s PHP and SQL. And now that I think about it, maybe it’s cause my PHP hasn’t been processed by the server yet…
Anyway, what I want to do is get this rss.php page to spit out XML and save it to a file called rss.xml. Also, can I control how often this happens? Or will it happen every time the page loads?
The answer to my question turned out to be that I DIDN’T need the page to be an XML document at all. As long as the declaration at the beginning says it’s XML, its fine. Here’s what I did. Remember place this at the VERY TOP of the PHP page.