当前位置: 首页 > 图文教程 > 网络编程 > PHP > 理解Zend 框架(4): 用Zend_HTTP_Client 获取无提要的内容

PHP
一贴学会PHP 新手入门教程
用PHP的ob_start() 控制您的浏览器cache
谈谈新手如何学习PHP 默默经典版本
黑夜路人出的几道php笔试题
一些 PHP 管理系统程序中的后门
用php获取本周,上周,本月,上月,本季度日期的代码
PHP 简单数组排序实现代码
PHP 多维数组排序实现代码
php 全局变量范围分析
php_xmlhttp 乱码问题解决方法
PHP 数组学习排序全接触
php Sql Server连接失败问题及解决办法
PHP 翻页 实例代码
php 随机数的产生、页面跳转、件读写、文件重命名、switch语句
PHP 5.3.0 安装分析心得
php 生成WML页面方法详解
php 取得瑞年与平年的天数的代码
php empty函数 使用说明
php natsort内核函数浅析
PHP 源代码分析 Zend HashTable详解

PHP 中的 理解Zend 框架(4): 用Zend_HTTP_Client 获取无提要的内容


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 170 ::
收藏到网摘: n/a

    并非所有的站点都包含提要,但是跟进某个地方的所有改动仍然是很有用的。本文将介绍如何使用 Zend_HTTP_Client 模块创建代理,从而将数据提取到提要阅读器界面中。在本文中,您将学到:

如何使用 Zend_HTTP_Client 模块加载网站数据。
如何保存提要条目的全文以及那些不支持提要的网页的全文。
如何在提要阅读器界面中阅读已保存提要条目的全文。
在本文的末尾,将完成提要阅读器应用程序的框架。首先,修改数据库纲要,其次,更新代码以支持新的纲要,然后添加将提要条目和网页保存到数据库中的功能。最后,使用 Zend_HTTP_Client 模块支持用户有选择地将条目保存到数据库中,并在已更新的在线提要阅读器中查看它们。

更新数据库纲要

为了将提要条目保存到提要阅读器界面中,首先我们需要更新数据库纲要。在 MySQL 控制台中键入清单 1 中的SQL 语句。


清单 1. 更改数据库纲要

drop table feeds;

create table feeds
(feedname varchar(256), link varchar(512), rss varchar(5));

insert into feeds values
('Fox Sports',
 'http://feeds.feedburner.com/foxsports/rss/headlines',
 'true'),
('Google News',
 'http://news.google.com/?output=rss',
 'true'),
('Yahoo News',
 'http://rss.news.yahoo.com/rss/topstories',
 'true'),
('phpbb',
 'http://www.phpbb.com/phpBB/viewforum.php?f=14',
 'false'),
('MySQL Forums :: PHP',
 'http://forums.mysql.com/list.php?52',
 'false'),
('SitePoint Forums :: PHP',
 'http://www.sitepoint.com/forums/forumdisplay.php?forumid=34',
 'false');

drop table savedentries;

create table savedentries
(username varchar(20), feedname varchar(256), channelname varchar(256),
 link varchar(512), entrysaved varchar(5), entrydata varchar(307200));
 


您能看到 feeds 表添加了一个新的字段:rss。这个字段用于辨别该提要是 RSS 提要还是不支持提要的网页。订阅列表中添加了另外三个不同 PHP 论坛的提要。请注意,对于第 3 部分中的提要,这个新字段值为 true,而三条新提要的值则为 false,这说明它们是网页,而非 RSS 提要。savedentries 表有两个新的字段:entrysaved 和 entrydata。entrysaved 字段说明 entrydata 字段中的数据是有效数据。entrydata 字段保存了该文章的全文。新的可订阅网页如图 1 所示。

现在需要回到第 3 部分的代码中做一些更改。

更新 IndexController 类

稍后我们将对 viewFeeds 视图进行更新,这需要当前用户所订阅的非 RSS 提要的列表,该列表列出了已订阅的提要和网页。在 IndexController 类中更改 indexAction 方法,如下所示。


清单 2. IndexController 类中的 indexAction 方法

    public function indexAction()
    {
...
            $select->where('feeds.feedname=subscribedfeeds.feedname');
            $select->where('feeds.rss=?', 'true');
            $rssResults = $db->fetchAll($select);

            $select = $db->select();
            $select->from('subscribedfeeds, feeds', '*');
            $select->where('subscribedfeeds.Username = ?', $username);
            $select->where('feeds.feedname=subscribedfeeds.feedname');
            $select->where('feeds.rss=?', 'false');
            $webResults = $db->fetchAll($select);

            $view = Zend::registry('view');
            $view->username = $us