Page 1 of 1

RSS easier way?

Posted: Tue Dec 14, 2004 9:39 am
by LostOne
I wanted to read RSS files: this is what I came up with....It works great, but how could I have done it easier?

$html=file_get_contents($url);
$html = explode("<title>", $html);//gets all of the title items into array
echo "<table>";
for($i = 3; $i<count($html);$i++)//want to start on first news story
{
echo "<tr><td>";
$data = str_replace("<title>", "", $html[$i]);//takes out title tag
$data = str_replace("</title>", ")", $data);//takes out title tag replaces with )
$data = str_replace("<description>", "", $data);//takes out description tag
$data = str_replace("</description>", ")", $data);//takes out description tag replaces with )
$data = str_replace("<link>", "", $data);//takes out link tag
$data = str_replace("</link>", ")", $data);//takes out link tag replaces with )
$data = str_replace("</item>", "", $data);//takes out item tag

$moredata = explode(")", $data);// gets array parts seperated by )
$title = $moredata[1];
$title = ltrim($title);
$description = $moredata[0];
$description = ltrim($description);
$link = $moredata[2];
$link = ltrim($link);
?>
<a href="<?=$link;?>" title="<?=$title;?>"><?=$description;?></a>
<?php
echo "</td></tr>";
}
echo "</table>";
}

Posted: Tue Dec 14, 2004 9:48 am
by timvw

Posted: Tue Dec 14, 2004 4:52 pm
by Simon
Well you could use the XML parsing functions, but in my experience, the ones available in 4.3.x are pretty awkward and would involve a similar amount of code as that. Could be good practice though, because XML can be really useful when you're good at it.

< Simon >