検索
ホームページphp教程php手册RSS2.0を生成するphpクラス

rss

/*****************************************
*           RSS2.0 Generator
*          Create by MagicBoy(darasion)
*          Copyright ? 神奇男孩
******************************************/

/*————————————————

使用方法:
将下面的数组,带入相应的函数。

1、频道主体
$channel = array(
 title => '频道名称(必备)',
 link => '频道的URL(必备)',
 description => '频道的描述(必备)',
 language => '频道文章所用语言(可选)',
 webmaster => '负责频道技术事务的网站管理员email(可选)',
 managingEditor => '责任编辑的email(可选)',
 pubDate => '频道内容发布日期,格式遵循RFC822格式(年份可为2位或4位)(可选)',
 lastBuildDate => '频道内容最后的修改日期(Sat, 07 Sep 2002 09:42:31 GMT)(可选)',
 skipDays => '提示新闻聚合器,那些天它可以跳过。(可选)',
 copyright => '频道内容的版权说明(可选)',
 ttl => '有效期,用以指明该频道可被缓存的最长时间(可选)',
);

2、频道图片
$image = array(
 url => '图片的链接(必备)',
 title => '图片的标题,用于http的alt属性(必备)',
 link => '网站的url(实际中常以频道的url代替)(必备)',
 width => '图片的宽度(象素为单位)最大144,默认88(可选)',
 height => '图片的高度(象素为单位)最大400,默认31(可选)',
 description => '用于link的title属性(可选)'
   );

3、频道项
$item = array(
 title => '项(item)的标题(必备)',
 description => '项的大纲(必备)',
 link => '项的URL(必备)',
 comments => '该项的评论(comments)页的URL(可选)',
 guid => '1项的唯一标志符串(可选)',
 author => '该项作者的email(可选)',
 enclosure => '描述该附带的媒体对象(可选)',
 category => '包含该项的一个或几个分类(catogory)(可选)',
 pubdate => '项的发布时间(可选)',
 source_url => '该项来自的RSS道(可选)',
 source_name => '该项来自的RSS道(可选)'
);
————————————————*/

class rss2
{
 var $channel_pre="";
 var $str_image="";
 var $str_item="";
 var $channel_end="";
 /*构造函数*/
 function rss2($channel,$encoding="GB2312")
  {
   $this->channel($channel,$encoding);
  }
 /*生成频道主体*/
 function channel($channel,$encoding="GB2312")
  {
  $this->channel_pre.="\n";
  $this->channel_pre.= "\n";

  $this->channel_pre.= " \n";

  $this->channel_pre.= "  ".$channel['title']."\n";//频道名称(必备)
  $this->channel_pre.= "  ".$channel['link']."\n";//频道的URL(必备)
  $this->channel_pre.= "  ".$channel['description']."\n";//频道的描述(必备)
  $this->channel_pre.= "  MagicBoy RSS Generator v1.0\n";//创建此文档的程序(可选)

  if(isset($channel['language']))$this->channel_pre.= "  ".$channel['language']."\n";//频道文章所用语言(可选)
  if(isset($channel['webmaster']))$this->channel_pre.= "  ".$channel['webmaster']."\n";//负责频道技术事务的网站管理员email(可选)
  if(isset($channel['managingeditor']))$this->channel_pre.= "  ".$channel['managingeditor']."\n";//责任编辑的email(可选)
  if(isset($channel['pubdate']))$this->channel_pre.= "  ".$channel['pubdate']."\n";//频道内容发布日期,格式遵循RFC822格式(年份可为2位或4位)(可选)
  if(isset($channel['lastbuilddate']))$this->channel_pre.= "  ".$channel['lastbuilddate']."\n";//频道内容最后的修改日期(Sat, 07 Sep 2002 09:42:31 GMT)(可选)
  if(isset($channel['skipdays']))$this->channel_pre.= "  ".$channel['skipdays']."\n";//提示新闻聚合器,那些天它可以跳过。(可选)
  if(isset($channel['copyright']))$this->channel_pre.= "  ".$channel['copyright']."\n";//频道内容的版权说明(可选)
  if(isset($channel['ttl']))$this->channel_pre.= "  ".$channel['ttl']."\n";//有效期,用以指明该频道可被缓存的最长时间(可选)

  $this->channel_end.= " \n";
  $this->channel_end.= "\n";
 }
 /*生成频道图片*/
 function image($image)
 {
  if(isset($this->str_image))unset($this->str_image);
  $this->str_image.= "  \n";
  if(isset($image['url']))$this->str_image.= "   ".$image['url']."\n";//图片的url(必备)
  if(isset($image['title']))$this->str_image.= "   ".$image['title']."\n";//图片的标题,用于http的alt属性(必备)
  if(isset($image['link']))$this->str_image.= "   ".$image['link']."\n";//网站的url(实际中常以频道的url代替)(必备)
  if(isset($image['width']))$this->str_image.= "   ".$image['width']."\n";//图片的宽度(象素为单位)最大144,默认88(可选)
  if(isset($image['height']))$this->str_image.= "   ".$image['height']."\n";//图片的高度(象素为单位)最大400,默认31(可选)
  if(isset($image['description']))$this->str_image.= "   ".$image['description']."\n";//用于link的title属性(可选)
  $this->str_image.= "  \n";
 }
 /*频道项*/
 function item($item)
 {
  $this->str_item.="  \n";
  $this->str_item.="   ".$item['title']."\n";//项(item)的标题(必备)
  $this->str_item.="   ".$item['description']."\n";//项的大纲(必备)
  $this->str_item.="   ".$item['link']."\n";//项的URL(必备)

if(isset($item['comments']))$this->str_item.=" ".$item['comments']."n";//Thisアイテムのコメント ページの URL (オプション)
if(isset($item['guid']))$this->str_item.=" ".$item['guid'] "n";//1 項目の一意の識別文字列 (オプション)
if(isset($item['author']))$this->str_item.=" " .$item[' author']."n";//アイテムの作成者のメールアドレス (オプション)
if(isset($item['enclosure']))$this->str_item. ;enclosure>".$item['enclosure']."n";//添付されたメディア オブジェクトを記述します (オプション)
if(isset($item['category']) )$this-> ;str_item.=" ".$item['category']."n";//このアイテムの 1 つまたは複数のカテゴリ (カテゴリ) が含まれます (オプション)
if(isset($ item['pubdate']))$this->str_item.=" ".$item['pubdate']."n";//item リリース時間 (オプション)
if (isset($item['source_url']))$this->str_item.=" ".$item['source_name'] ."n";//このアイテムの送信元の RSS チャネル (オプション)
$this->str_item.=" n";
}
/*出力 xml*/
関数generate()
{
if(isset($this->channel_pre)&&isset($this->channel_end)&&isset($this->str_item))
{
ヘッダー("Content-type:text/ xml");
echo $this->channel_pre;
echo $this->str_image;
echo $this->str_item;
echo $this->channel_end;
}
}
/*チャンネルを消去* /
function Erase_channel()
{
unset($this->channel_pre);
unset($this->channel_end);
}
/*チャンネル画像を消去*/
function Erase_image()
{
unset( $this->str_image);
}
/*アイテムを消去*/
function Erase_item()
{
unset($this->str_item);
}
/ *すべて消去*/
function Erase()
{
$this->erase_channel();
$this->erase_image();
$this->erase_item();
}
}
?> ;



声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)