[991]PHP網站開發 進階應用技巧2
<?php
require_once "simplepie.inc";
$rss_url[] = 'http://www.mobile01.com/rss/newtopics.xml';
$rss_url[] = 'http://tw.news.yahoo.com/rss/realtime';
$rss_url[] = 'http://udn.com/udnrss/BREAKINGNEWS1.xml';
$feed = new SimplePie();
$feed->set_feed_url($rss_url);
$feed->init();
$feed->handle_content_type();
$feed->set_item_limit(10);
$web_title= $feed->get_title();
$web_link= $feed->get_link();
$items= $feed->get_items(0,10);
foreach ($items as $item){
$web_title=$item->get_feed()->get_title();
$web_link=$item->get_feed()->get_link();
$title=$item->get_title();
$url=$item->get_link();
$date=$item->get_date("Y-m-d H:i:s");
$desc=$item->get_description();
$all_title.="<li>[<a href='$web_link'>$web_title</a>] <b><a href='$url' style='color:#202020;text-decoration:none;'>$title</a></b>
<span style='color:#0099ff;font-size:12px;'>({$date})</span>
<div style='color:gray;font-size:12px;margin-bottom:6px;'>$desc</div></li>";
}
$main="
<div align='center'>
<h1>$web_title</h1>
<a href='$web_link'>$web_link</a>
</div>
<ol>
$all_title
</ol>
";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel='stylesheet' href='style.css' type='text/css' />
<title></title>
<script type="text/javascript" language="javascript" src="lytebox.js"></script>
<link rel="stylesheet" href="lytebox.css" type="text/css" media="screen" />
</head>
<body>
<div id='news' style='width:500px;'>
<?php echo $main; ?>
</div>
</body>
</html>