Thursday, June 12, 2008

PHP4 でのRSS リーダー sample

http://keithdevens.com/software/phpxml
からPHP XML Libraryをとってくる。


<?php // Load and parse the XML document

$url = 'http://hogehoge/blog/?feed=rss2';

$xml_data1 = file_get_contents($url) or die();

require_once('xml.php');
$xml_array = XML_unserialize($xml_data1);
$items = $xml_array['rss']['channel']['item'];
unset ($xml_array);
unset ($xml_data1);

foreach ($items as $item) {
echo "<h3><a href='" . $item['link'] . "'>" . $item['title'] . "</a></h3>";
echo "<p>" . mb_strimwidth($item['description'], 0, 60, "...",'utf8') . "</p>";
break;

}
unset ($items);


?>

No comments: