XML code help please

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

XML code help please

Post by mesz »

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.

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>
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Hmmm.... i would have thought that what you have would have worked....

but if u need to write it to and xml file
look up PHP's fwrite() function
of course after you save the xml file u need to header("Location: xmlfile")
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

it's sorted...cheers for getting back to us though man.
There were problems with whitespace and unclosed tags.
Post Reply