Categorized | Biocompute

Tags | , ,

简单而完整的 PHP RSS 阅读器

Posted on 06 五月 2009 by 柳城 ,阅读 736

假设需要一个 PHP 页面将 RSS 提要(feed)转化成 HTML。RSS 是一种简单的 XML 格式用于发布连锁内容。文档的根元素是 rss,它包括一个 channel 元素。channel 元素包含关于提要的元数据,如标题、语言和 URL。它还包含各种封装在 item 元素中的报道。每个 item 都有一个 link 元素,包括一个 URL,还有 title 或 description(通常两者都有),包含普通文本。不使用名称空间。RSS 的内容当然不止这些,不过对本文来说知道这些就足够了。

<?php // Load and parse the XML document
$rss =  simplexml_load_file('http://partners.userland.com/nytRss/nytHomepage.xml');
$title =  $rss->channel->title;
?>
<html xml:lang="en" lang="en">
<head>
  <title><?php echo $title; ?></title>
</head>
<body>

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

<?php
// Here we'll put a loop to include each item's title and description
foreach ($rss->channel->item as $item) {
  echo "<h2><a href='" . $item->link . "'>" . $item->title . "</a></h2>";
  echo "<p>" . $item->description . "</p>";
}
?>

</body>
</html>

这样就用 PHP 完成了一个简单的 RSS 阅读器:只需要几行 HTML 和几行 PHP。不算空白的话一共只有 20 行。当然,这个实现的功能还不够丰富,也不够优化或者健壮。我们来看看还能做什么。

转载请注明 : 来源于 简单而完整的 PHP RSS 阅读器 | 柳城

赞助商

2条评论 于 “简单而完整的 PHP RSS 阅读器”

  1. bolo bolo Says:

    不错的源码,拿走了

    [回复]

  2. 成都治疗癫痫 成都治疗癫痫 Says:

    这个可以学习下。说的不错,支持

    [回复]

Leave a Reply

广告招租

[强] [握手] [可爱] [ok] [呲牙] :) [偷笑] [流泪] [疑问] [亲亲] [擦汗] [得意] [衰] [可怜] [抱拳] [坏笑] more »

无觅相关文章插件,快速提升流量

adobe free

adobe free

winrar 3 download

winrar 3 download freedownload

windows 7 free

windows 7 crack

key office 2010

office 2010 key

download photo shop free

photo shop serial

corel dvd moviefactory 6

corel dvd moviefactory 6 downloads

free corel photoshop download

free corel photoshop download keygen

photoshop key

photoshop key

free corel downloads

free corel downloads cracked

free winrar download for xp

download winrar for xp for free

serial corel draw 11

serial corel draw 11 serials

windows 7 key

windows 7 key

photo shop key

photo shop key

winrar password cracker serial

wirar password cracker

serial winzip 11

serial winzip 11 key

cs5 serialz

cs5 serialz free

office 2010 professional key

office 2010 key

office 2010 free

office 2010 key

windows key

windows key