喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 喜悦证交所 | 帮助

RSS 订阅当前论坛  

[北京]代朋友公司招聘PHP高级程序员多名

上一主题 下一主题
     
标题: [讨论] 关于RSS的用法,有谁知道.  
 
wgllz
注册会员
Rank: 2


UID 98433
精华 0
积分 68
帖子 36
金钱 68 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2007-9-12
状态 离线
关于RSS的用法,有谁知道.

我想做一个网站,就是读取RSS的内容,就像www.xianguo.com  和  www.zhuaxia.com  一样的功能,现在没有什么思路,大家给点思路和想法!



陕西培训114网站长
http://www.sxpx114.com
新学php希望大家指导
2008-6-24 09:11 AM#1
查看资料  访问主页  发短消息  顶部
 
奶瓶 (NP博士)
版主
Rank: 7Rank: 7Rank: 7
老仙


UID 52707
精华 4
积分 5438
帖子 6041
金钱 5388 喜悦币
威望 50
人脉 0
阅读权限 100
注册 2004-11-22
来自 北大中文系
状态 在线
[推荐阅读] 时间函数
你什么地方没有思路?
哪个环节没有想法?





图片包子,注册送100包子!
2008-6-24 11:54 AM#2
查看资料  访问主页  Blog  发短消息  QQ  ICQ 状态  Yahoo!  顶部
 
wgllz
注册会员
Rank: 2


UID 98433
精华 0
积分 68
帖子 36
金钱 68 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2007-9-12
状态 离线
[推荐阅读] 实训中国《PHP实战培训班》(长期招生,随到随学)
回复 #2 奶瓶 的帖子

就是如何用PHP读rss,如何实现实时更新的.就是关于RSS的一些知识.



陕西培训114网站长
http://www.sxpx114.com
新学php希望大家指导
2008-6-24 12:11 PM#3
查看资料  访问主页  发短消息  顶部
 
奶瓶 (NP博士)
版主
Rank: 7Rank: 7Rank: 7
老仙


UID 52707
精华 4
积分 5438
帖子 6041
金钱 5388 喜悦币
威望 50
人脉 0
阅读权限 100
注册 2004-11-22
来自 北大中文系
状态 在线
[推荐阅读] JS+PHP广告横幅 仿DZ
RSS你可以选择解析成数组,也可以直接用css、xlst什么的把它格式化了
解析RSS的东西很多,phpclasses上搜能搜到,直接用php的xmlparaser解析一下也可以凑合用
RSS有三种常用标准,RSS0.91/RSS1.0/RSS2.0,其中2.0是0.9x上发展来的,和1.0其实无继承关系,是两伙人搞的,所以结构有点区别

这是简单的拆解过程:

<?php

/**
BSMLITE PROJECT

* Category : library
* Filename : feed_parser.lib.php
* Author : Dr.NP <[email]bssoft@263.net[/email]>
* Copyright (c) : 2006-2008 BS.Group, all rights reserved
* Version : 1.0.1

LICENSE

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <[url]http://www.gnu.org/licenses/[/url]>.

DESCRIPTION

* Feed parser - RSS 0.9 / RSS 1.0 / RSS 2.0 / ATOM feeds

CHANGELOG

* 05/08/2008 (1.0.0) - Library creation
* 05/15/2008 (1.0.1) - ATOM supported

PACKAGE
* @package bsm

*/

class BsmFeedParser
{
    var 
$classname                'BsmFeedParser';
    
    
// Feed content
    
var $version;
    var 
$content                '';
    
    
// Feed content
    
var $title;
    var 
$ttl;
    var 
$date;
    var 
$image;
    
    
// Return value
    
var $feed                    = array();
    
    
// Tag
    
var $depth                    = array();
    
    
// Objects
    
var $xml_parser;
    
    
// status
    
var $in_item                false;
    var 
$in_image                false;
    var 
$in_entry                false;
    var 
$current_element        '';
    var 
$current_item            0;
    
    
// Constructor
    
function __construct($content null)
    {
        if (
$content)
        {
            
$this->content $content;
        }
    }
    
    
// Set feed content
    // You can use BSM's net library to fetch content by passing URLs
    
public function set_content($content)
    {
        if (
$content)
        {
            
$this->content $content;
        }
    }
    
    
// Rarse it
    
public function parse()
    {
        
$this->xml_parser xml_parser_create();
        
        
xml_set_object($this->xml_parser$this);
        
xml_set_element_handler($this->xml_parser'_tag_open''_tag_close');
        
xml_set_character_data_handler($this->xml_parser'_tag_data');
        
        
xml_parse($this->xml_parser$this->content);
        
        return 
$this->_rebuild_feed();
    }
    
    
// Handler: Tag open
    
private function _tag_open($parser$tag_name$tag_attrib)
    {
        
$this->current_element strtoupper($tag_name);
        if (
'ITEM' == strtoupper($tag_name))
        {
            
$this->in_item true;
            
$this->version 'RSS';
            
$this->feed['VERSION'] = 'RSS';
        }
        
        if (
'IMAGE' == strtoupper($tag_name))
        {
            
$this->in_image true;
        }
        
        if (
'ENTRY' == strtoupper($tag_name))
        {
            
$this->in_entry true;
            
$this->version 'ATOM';
            
$this->feed['VERSION'] = 'ATOM';
        }
    }
    
    
// Handler: Tag close
    
private function _tag_close($parser$tag_name)
    {
        
$this->current_element '';
        
        if (
'ITEM' == strtoupper($tag_name))
        {
            
$this->in_item false;
            
$this->current_item ++;
        }
        
        if (
'IMAGE' == strtoupper($tag_name))
        {
            
$this->in_image false;
        }
        
        if (
'ENTRY' == strtoupper($tag_name))
        {
            
$this->in_entry false;
            
$this->current_item ++;
        }
    }
    
    
// Handler: Tag data
    
private function _tag_data($parser$data)
    {
        
$tag_name $this->current_element;
        
$data trim($data);
        
$data preg_replace("/[r|n]/s"''$data);
        
        if (!
$this->in_item && !$this->in_entry)
        {
            
// RSS attribute
            
if ($tag_name)
            {
                if (!
$this->in_image)
                {
                    
$this->feed[$tag_name] .= $data;
                }
                
                else if (
$tag_name != 'IMAGE')
                {
                    
$this->feed['IMAGE'][$tag_name] .= $data;
                }
            }
        }
        
        else
        {
            
// In item
            
if ($tag_name && $tag_name != 'ITEM' && $tag_name != 'ENTRY')
            {
                if (!
$this->in_image)
                {
                    
$this->feed['FEED'][$this->current_item][$tag_name] .= $data;
                }
                
                else if (
$tag_name != 'IMAGE')
                {
                    
$this->feed['FEED'][$this->current_item]['IMAGE'][$tag_name] .= $data;
                }
            }
        }
    }
    
    
// Rebuild
    
private function _rebuild_feed()
    {
        for (
$i 0$i count($this->feed['feed']); $i++)
        {
            
// RSS
            
if ($this->feed['FEED'][$i]['DC:DATE'])
            {
                
$this->feed['FEED'][$i]['PUBTIMESTAMP'] = strtotime($this->feed['FEED'][$i]['DC:DATE']);
            }
            
            else if (
$this->feed['FEED'][$i]['PUBDATE'])
            {
                
$this->feed['FEED'][$i]['PUBTIMESTAMP'] = strtotime($this->feed['FEED'][$i]['PUBDATE']);
            }
            
            
// ATOM
            
else if ($this->feed['FEED'][$i]['PUBLISHED'])
            {
                
$this->feed['FEED'][$i]['PUBTIMESTAMP'] = strtotime($this->feed['FEED'][$i]['PUBLISHED']);
            }
            
            else if (
$this->feed['FEED'][$i]['UPDATED'])
            {
                
$this->feed['FEED'][$i]['PUBTIMESTAMP'] = strtotime($this->feed['FEED'][$i]['UPDATED']);
            }
            
            
// RSS 0.9x
            
if (!$this->feed['FEED'][$i]['PUBTIMESTAMP'])
            {
                
$this->feed['FEED'][$i]['PUBTIMESTAMP'] = time();
            }
            
            
// ATOM
            
if (!$this->feed['FEED'][$i]['DESCRIPTION'])
            {
                
$this->feed['FEED'][$i]['DESCRIPTION'] = $this->feed['FEED'][$i]['SUMMARY'] ? $this->feed['FEED'][$i]['SUMMARY'] : 'NO DESCRIPTION';
            }
        }
        
        return 
$this->feed;
    }
}

// Current class name
$classname 'BsmFeedParser';
?>





图片包子,注册送100包子!
2008-6-24 12:25 PM#4
查看资料  访问主页  Blog  发短消息  QQ  ICQ 状态  Yahoo!  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.040663 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP