XML code help please
Posted: Mon Oct 03, 2005 3:09 am
Hello,
I am writing an XML page to parse a plain text file into XML so that it can be displayed in a news aggregator.
My page displays as a php page, but will display in the news aggregator.
I am guessing it is because it is still a php page and not an xml page.
I suppose the two questions are is my theory correct?
And how do I save my page on the fly to an xml file so that this can be viewed and the nodes can be expanded and collapsed?
Any ideas people.
I am writing an XML page to parse a plain text file into XML so that it can be displayed in a news aggregator.
My page displays as a php page, but will display in the news aggregator.
I am guessing it is because it is still a php page and not an xml page.
I suppose the two questions are is my theory correct?
And how do I save my page on the fly to an xml file so that this can be viewed and the nodes can be expanded and collapsed?
Any ideas people.
Code: Select all
<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n
<rss version=\"2.0\">";
?>
<?php
$data = file('news.txt');
$data = array_reverse($data);
foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
$pieces[4] = preg_replace('!\[url=(.+?)\](.+?)\[/url\]!Uim', '<a href="\1" target=\"_blank\">\2</a>', $pieces[4]);
$pieces[5] = preg_replace('!\[img\](.+?)\[/img\]!', '<img src="\1">',$pieces[5]);
echo"
<channel>
<item>
<link><a href=\"http://url/page.php#$pieces[3]\">$pieces[3]</a></link>\n
<description>".$pieces[6]."</description>\n
</item>\n
</channel>
";
}
?>
</rss>