php rss分析类程序

<?php

class rss74 {

    // RSS feed title:
    var $title = "Untitled";
   
    // RSS description:
    var $desc = "";
   
    // RSS base url
    // -> Example: http://www.jonasjohn.de/
    var $base_url = "";
   
    // XSL file for the resulting RSS feed:
    var $xsl_file = 'rss.xsl';
   
    // RSS 2.0 Specification (URL):
    var $doc_url = 'http://blogs.law.harvard.edu/tech/rss';
   
    // Copyright text:
    // -> Example: Copyright 2006, Jonas John
    var $copyright = '';
   
    // RSS language setting:
    // Example: en-us, de-de, fr-fr
    var $language = 'en-us';
   
    // Managing editor and webmaster:
    // (should contain a E-Mail adress)
    var $managing_editor = '';
    var $webmaster = '';
   
    // Feedburner URL
    // Example: http://feeds.feedburner.com/codedump-rss
    // (If a FB URL is set, all requests except the Feedburner and Google
    // requests will be redricted to the feedburner URL)
    var $feedburner_url = '';
   
    // RSS generator:
    var $generator = 'rss74/v0.3';
   
    // Limit RSS entries to:
    // (Example: 20, 30, 40, 50, etc.)
    var $limit_entries = 20;

    // RSS items:
    var $items = array();

    // constructor:
    function rss74(){
    }  
   
    function add_entry($entry){   
   
        // create date key:
        $date = isset($entry['date']) ? $entry['date'] : time();  

        // add unique string:
        $date .= '_' . md5($entry['title']);
       
        $this->items[$date] = $entry;
    }
   
    function _get_val(&$array, $key){
        return isset($array[$key]) ? $array[$key] : '';
    }
   
    function _exists_val(&$array, $key){
        return isset($array[$key]);
    }
   
    function get_rss_headers($rss_webpath){
        return '<link rel="alternate" type="application/rss+xml" title="RSS" href="'.$rss_webpath.'" />';
    }
   
    function print_rss(){
        global $_SERVER;
   
        krsort($this->items);
        $this->items = array_slice($this->items, 0, $this->limit_entries);
       
        $first_item = array_keys($this->items);
        $first_item = $first_item[0];
       
        $last_change = $this->items[$first_item]['date'];
        header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_change).' GMT');
       
        header('Content-Type: text/xml; charset=utf-8');

        if (!empty($this->feedburner_url)){
            if (!preg_match("/feedburner/i", $_SERVER['HTTP_USER_AGENT']) and !preg_match("/google/i", $_SERVER['HTTP_USER_AGENT'])) {
                header('HTTP/1.1 301 Moved Permanently');
                header('Location: ' . $this->feedburner_url);
                print '<a href="'.$this->feedburner_url.'">Redirecting...</a>';
                return true;
            }
        }

        print '<?xml version="1.0" encoding="utf-8"?>' . " ";
       
        if ($this->xsl_file != '')
            print '<?xml-stylesheet href="rss.xsl" type="text/xsl" media="screen"?>' . " ";
       
        print '<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">]>' . " ";
       
        print "<!-- Hello! This web page is a RSS file that is meant to be read by a RSS reader application. Look at http://en.wikipedia.org/wiki/RSS to learn more about RSS. -->";
       
        print '<rss version="2.0" xmlns:xhtml="http://www.w3.org/1999/xhtml">' . " ";
        print '<channel>' . " ";
       
        print " ".'<title>'.htmlentities($this->title).'</title>' . " ";
       
        if (!empty($this->desc))
            print " ".'<description>'.htmlentities($this->desc).'</description>' . " ";
       
        if (!empty($this->base_url))
            print " ".'<link>'.htmlentities($this->base_url).'</link>' . " ";
       
        print " ".'<lastBuildDate>'.date('r', time()).'</lastBuildDate>' . " ";
        print " ".'<pubDate>'.date('r', time()).'</pubDate>' . " ";
       
        if (!empty($this->generator))
            print " ".'<generator>'.$this->generator.'</generator>' . " ";
       
        if (!empty($this->copyright))
            print " ".'<copyright>'.$this->copyright.'</copyright>' . " ";
           
        if (!empty($this->doc_url))
            print " ".'<docs>'.$this->doc_url.'</docs>' . " ";
       
        if (!empty($this->language))
            print " <language>".$this->language."</language> ";
           
        if (!empty($this->managing_editor))
            print " <managingEditor>".$this->managing_editor."</managingEditor> ";

        if (!empty($this->webmaster))
            print " <webMaster>".$this->webmaster."</webMaster> ";

        while(list($num, $item) = each($this->items)){
     
            print " <item> ";
            print " <title>".htmlentities($this->_get_val($item, 'title'))."</title> ";
           
            if ($this->_exists_val($item, 'url')){
                print " <link>".$this->_get_val($item, 'url')."</link> ";
                print " <guid isPermaLink="true">".$this->_get_val($item, 'url')."</guid> ";
            }
           
            if ($this->_exists_val($item, 'desc'))
                print " <description><![CDATA[".$this->_get_val($item, 'desc')."]]></description> ";
           
            if ($this->_exists_val($item, 'date')){
                print " <pubDate>".date('r', intval($this->_get_val($item, 'date')))."</pubDate> ";
            }
       
            $cats = array();
            while(list($cn, $citem) = each($cats)){
                print " <category>$citem</category> ";
            }
               
            print " </item> ";
            
        }

        print " </channel> ";
        print "</rss>";
       
        return true;
       
    }
}

实例

 include('inc.rss74.php');

    // RSS items list:
    $example_list = array();   
       
    /*
    ** Create some test entries:
    */
   
    $m = rand(8, 30);
    for ($x = 0; $x < $m; $x++){
   
        // create a random UNIX-Timestamp:
        $date = rand(1166000000, 1166400000);
   
        $example_list[] = array(
            'title' => 'Example RSS message #' . $x,
            'url' => 'http://www.jonasjohn.de/#' . $x,
            'desc' => 'This is a example message from RSS74!',
            'date' => $date
        );
   
    }
   
   
    // create new RSS object:
    $rss = new rss74();
   
    /*
    ** Set RSS informations:
    */
   
    // RSS title:
    $rss->title = 'RSS example 2';
   
    // RSS description:
    $rss->desc = 'This feed shows some random entries.';
   
    // base URL of your homepage:
    $rss->base_url = 'http://www.example.org/';
   
    // limit entry count to 20
    $rss->limit_entries = 20;
   
    // RSS Editor
    $rss->managing_editor = 'Yourname <yourname@example.org>';

    // Webmaster name
    $rss->webmaster = 'Yourname <yourname@example.org>';
   
    // language:
    $rss->language = 'en-us';
   
    // Copyright message:
    $rss->copyright = 'Copyright 2006, Yourname';
   
    // Set Feedburner adress:
    //$rss->feedburner_url = 'http://feeds.feedburner.com/codedump-rss';
    // (empty) = No redirection

    // Set "xsl_file" to empty to disable the XSL file:
    $rss->xsl_file = '';

    // Add entries to the RSS object:
    while (list($date, $entry) = each($example_list)){
              
        $rss->add_entry(array(
            'title'     => $entry['title'],
            'url'       => $entry['url'],
            'desc'      => $entry['desc'],
            'date'      => $entry['date']
        ));
   
    }
   
    // let rss74 do the rest:
    $rss->print_rss();

?>

 

时间: 2024-10-03 10:15:28

php rss分析类程序的相关文章

使用Eclipse Callisto分析应用程序

Eclipse(Eclipse 3.2)的最新版本带有Callisto,一套丰富的针对Eclipse 3.2的可选插件.Callisto包括一个功能强大的分析工具,此工具称为Eclipse测试与性能工具平台,简称TPTP.TPTP提供了一套功能全面的开源性能-测试和分析工具,包括集成的应用程序监控.测试.跟踪和分析功能,以及静态代码分析工具.对于在各类Java应用程序中找出和识别性能问题,分析工具的价值是不可估计的.在本文中,我们将探讨如何使用TPTP来保证获得高质量和高性能的代码(甚至是在单元

php实现的RSS生成类实例

  php实现的RSS生成类实例          这篇文章主要介绍了php实现的RSS生成类,实例分析了RSS生成类的原理.定义与使用技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了php实现的RSS生成类.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

php实现的RSS生成类实例_php技巧

本文实例讲述了php实现的RSS生成类.分享给大家供大家参考.具体如下: class RSS { var $title; var $link; var $description; var $language = "en-us"; var $pubDate; var $items; var $tags; function RSS() { $this->items = array(); $this->tags = array(); } function addItem($ite

如何利用JConsole观察分析Java程序的运行并进行排错调优_java

一.JConsole是什么 从Java 5开始 引入了 JConsole.JConsole 是一个内置 Java 性能分析器,可以从命令行或在 GUI shell 中运行.您可以轻松地使用 JConsole(或者,它更高端的 "近亲" VisualVM )来监控 Java 应用程序性能和跟踪 Java 中的代码. 二.如何启动JConsole 1.如果是从命令行启动,使 JDK 在 PATH 上,运行 jconsole 即可. 2.如果从 GUI shell 启动,找到 JDK 安装路

一个Banner管理类程序(转译)

程序 调用方式1.  .Banner(Width, Height)     .Banner方法是用来告诉Banner管理类程序你希望在客户端显示的是多大的Banner.   I.  Width: <Banner宽度>   II.  Height: <Banner高度> 2.  .Click(Banner_ID, Banner_URL)     这个方法是程序员很少使用的.它是作用是用在客户端单击Banner统计   I.  Banner_ID: <被单击Banner的编号&g

php类:XML文件分析类

XMLParser.class.php <?php /** XML 文件分析类 * Date: 2013-02-01 * Author: fdipzone * Ver: 1.0 * * func: * loadXmlFile($xmlfile) 读入xml文件输出Array * loadXmlString($xmlstring) 读入xmlstring 输出Array */ class XMLParser{ /** 读取xml文件 * @param String $xmlfile * @retu

PHP生成RSS文件类实例

 PHP RSS 生成类实例代码如下: 代码如下: <?php if (defined('_class_rss_php')) return; define('_class_rss_php教程',1); /**    *  使用说明:  *  $rss = new rss('redfox','http://jb51.net/',"redfox's blog");  *  $rss->additem('rss class',"http://www.jb51.net&q

java代码-java初学者提问 在类中 用static成员变量实例化自身类 程序的执行顺序过程是怎样的?

问题描述 java初学者提问 在类中 用static成员变量实例化自身类 程序的执行顺序过程是怎样的? class Demo03 { public static void main(String[] args) { A.show(); } } class A { //构造方法 A(){ System.out.println("构造方法执行"); System.out.println(b); System.out.println(c); } static A a=new A(); sta

win32-eclipse中File类程序运行报错

问题描述 eclipse中File类程序运行报错 程序如下: package nmd; import java.io.File; public class FileHello { public static void main(String[] args) { try { Runtime ec=Runtime.getRuntime(); File file=new File("file.txt"); ec.exec(file.getAbsolutePath()); } catch (E