Tuesday, June 10, 2008

rss reader by PHP5 (sample)

<?php

$feed = 'http://test.com/?feed=rss2';
$rss = simplexml_load_file($feed);
$title = $rss->channel->title;
?>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>

<h1><?php echo $title; ?></h1>

<?php
foreach ($rss->channel->item as $item) {
echo "<h3><a href='" . $item->link . "'>" . $item->title . "</a></h3>";
$pdate = $item->pubDate;
echo date("Y/m/d G:H:i",strtotime($pdate));
echo "<p>" . $item->description . "</p>";
echo "<p>" . $item->category . "</p>";
}
?>

</body>
</html>

No comments: