RSS easier way?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LostOne
Forum Newbie
Posts: 18
Joined: Wed Jul 28, 2004 3:21 pm
Location: Florida

RSS easier way?

Post 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>";
}
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Simon
Forum Newbie
Posts: 12
Joined: Sun Dec 12, 2004 11:36 pm

Post 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 >
Post Reply