最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 完美的rss 生成类
时间:2022-07-02 10:10:49 编辑:袖梨 来源:一聚教程网
class rssGenerator_rss
{
var $rss_version = '2.0';
var $encoding = '';
var $stylesheet = '';
function cData($str)
{
return '';
}
function createFeed($channel)
{
$selfUrl = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https教程://');
$selfUrl .= $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$rss = '
if (!empty($this->encoding)) {
$rss .= ' encoding="' . $this->encoding . '"';
}
$rss .= '?>' . " ";
if (!empty($this->stylesheet)) {
$rss .= $this->stylesheet . " ";
}
$rss .= '' . " ";
$rss .= '
$rss .= '
$rss .= '
$rss .= '
$rss .= ' ' . $channel->link . '' . " ";
$rss .= '
if (!empty($channel->language)) {
$rss .= '
}
if (!empty($channel->copyright)) {
$rss .= '
}
if (!empty($channel->managingEditor)) {
$rss .= '
}
if (!empty($channel->webMaster)) {
$rss .= '
}
if (!empty($channel->pubDate)) {
$rss .= '
}
if (!empty($channel->lastBuildDate)) {
$rss .= '
}
foreach ($channel->categories as $category) {
$rss .= '
$rss .= ' domain="' . $category['domain'] . '"';
}
$rss .= '>' . $category['name'] . '' . " ";
}
if (!empty($channel->generator)) {
$rss .= '
}
if (!empty($channel->docs)) {
$rss .= '
}
if (!empty($channel->ttl)) {
$rss .= '
}
if (sizeof($channel->skipHours)) {
$rss .= '
foreach ($channel->skipHours as $hour) {
$rss .= '
}
$rss .= '
}
if (sizeof($channel->skipDays)) {
$rss .= '
foreach ($channel->skipDays as $day) {
$rss .= '
}
$rss .= '
}
if (!empty($channel->image)) {
$image = $channel->image;
$rss .= '
$rss .= '
$rss .= '
$rss .= ' ' . $image->link . '' . " ";
if ($image->width) {
$rss .= '
}
if ($image->height) {
$rss .= '
}
if (!empty($image->description)) {
$rss .= '
}
$rss .= '
}
if (!empty($channel->textInput)) {
$textInput = $channel->textInput;
$rss .= '
$rss .= '
$rss .= '
$rss .= '
$rss .= ' ' . $textInput->link . '' . " ";
$rss .= '
}
if (!empty($channel->cloud_domain) || !empty($channel->cloud_path) || !empty($channel->cloud_registerProcedure) || !empty($channel->cloud_protocol)) {
$rss .= '
$rss .= 'registerProcedure="' . $channel->cloud_registerProcedure . '" ';
$rss .= 'protocol="' . $channel->cloud_protocol . '" />' . " ";
}
if (!empty($channel->extraXML)) {
$rss .= $channel->extraXML . " ";
}
foreach ($channel->items as $item) {
$rss .= '
if (!empty($item->title)) {
$rss .= '
}
if (!empty($item->description)) {
$rss .= '
}
if (!empty($item->link)) {
$rss .= ' ' . $item->link . '' . " ";
}
if (!empty($item->pubDate)) {
$rss .= '
}
if (!empty($item->author)) {
$rss .= '
}
if (!empty($item->comments)) {
$rss .= '
}
if (!empty($item->guid)) {
$rss .= '
$rss .= $item->guid . '
}
if (!empty($item->source)) {
$rss .= ' ' . " ";
}
if (!empty($item->enclosure_url) || !empty($item->enclosure_type)) {
$rss .= '
$rss .= 'type="' . $item->enclosure_type . '" />' . " ";
}
foreach ($item->categories as $category) {
$rss .= '
$rss .= ' domain="' . $category['domain'] . '"';
}
$rss .= '>' . $category['name'] . '' . " ";
}
$rss .= '
}
$rss .= '
return $rss .= '
}
}
class rssGenerator_channel
{
var $atomLinkHref = '';
var $title = '';
var $link = '';
var $description = '';
var $language = '';
var $copyright = '';
var $managingEditor = '';
var $webMaster = '';
var $pubDate = '';
var $lastBuildDate = '';
var $categories = array();
var $generator = '';
var $docs = '';
var $ttl = '';
var $image = '';
var $textInput = '';
var $skipHours = array();
var $skipDays = array();
var $cloud_domain = '';
var $cloud_port = '80';
var $cloud_path = '';
var $cloud_registerProcedure = '';
var $cloud_protocol = '';
var $items = array();
var $extraXML = '';
}
class rssGenerator_image
{
var $url = '';
var $title = '';
var $link = '';
var $;
var $;
var $description = '';
}
class rssGenerator_textInput
{
var $title = '';
var $description = '';
var $name = '';
var $link = '';
}
class rssGenerator_item
{
var $title = '';
var $description = '';
var $link = '';
var $author = '';
var $pubDate = '';
var $comments = '';
var $guid = '';
var $guid_isPermaLink = true;
var $source = '';
var $source_url = '';
var $enclosure_url = '';
var $enclosure_length = '0';
var $enclosure_type = '';
var $categories = array();
}
?>
实例
require_once 'rss_generator.inc.php';
$rss_channel = new rssGenerator_channel();
$rss_channel->atomLinkHref = '';
$rss_channel->title = 'My News';
$rss_channel->link = 'http://111cn.net教程/news.php';
$rss_channel->description = 'The latest news about web-development.';
$rss_channel->language = 'en-us';
$rss_channel->generator = 'PHP RSS Feed Generator';
$rss_channel->managingEditor = '[email protected] (Alex Jefferson)';
$rss_channel->webMaster = '[email protected] (Vagharshak Tozalakyan)';
$item = new rssGenerator_item();
$item->title = 'New website launched';
$item->description = 'Today I finaly launch a new website.';
$item->link = 'http://111com.net';
$item->guid = 'http://111com.net';
$item->pubDate = 'Tue, 07 Mar 2006 00:00:01 GMT';
$rss_channel->items[] = $item;
$item = new rssGenerator_item();
$item->title = 'Another website launched';
$item->description = 'Just another website launched.';
$item->link = 'http://111com.net';
$item->guid = 'http://111com.net';
$item->pubDate = 'Wed, 08 Mar 2006 00:00:01 GMT';
$rss_channel->items[] = $item;
$rss_feed = new rssGenerator_rss();
$rss_feed->encoding = 'UTF-8';
$rss_feed->version = '2.0';
header('Content-Type: text/xml');
echo $rss_feed->createFeed($rss_channel);
?>
相关文章
- 重返未来1999趋光性研究夜幕之外怎么玩 12-27
- 桃源深处有人家养怡尘世装饰大赛怎么玩 12-27
- 第五人格贪吃蛇大作战联动时装怎么样 12-27
- 绝区零直到苍白荒秽之地怎么玩 12-27
- 第五人格贪吃蛇大作战联动时装怎么样 贪吃蛇联动独特时装介绍 12-27
- 以闪亮之名龙族幻想联动怎么玩 以闪亮之名龙族幻想联动介绍 12-27