How to generate RSS subscription in php, phprss subscription_PHP tutorial
WBOY
Release: 2016-07-13 10:06:37
Original
842 people have browsed it
How to generate RSS subscription in php, phprss subscription
The example in this article describes how to generate RSS subscriptions in php. Share it with everyone for your reference. The specific analysis is as follows:
RSS (Really Simple Syndication, also called syndication) is a format for describing and synchronizing website content. RSS can be one of the following three interpretations: Really Simple Syndication; RDF (Resource Description Framework) Site Summary; Rich Site Summary. But in fact, these three explanations all refer to the same Syndication technology. RSS is currently widely used in online news channels, blogs and wikis. Using RSS subscriptions can obtain information faster. The website provides RSS output, which is helpful for users to obtain the latest updates of website content. Network users can use aggregation tool software that supports RSS on the client to read website content that supports RSS output without opening the website content page.
Technically speaking, an RSS file is a piece of standardized XML data. The file generally has rss, xml or rdf as the suffix. The following is an example of the content of an rss file:
Copy code The code is as follows:
Bangke’s Home
http://www.bkjia.com/ Bangkezhijia RSS Tutorial
Website address/rss New RSS tutorial on W3School
XML Tutorial
Website address/xml New XML tutorial on W3School
The following is a code example that uses php to dynamically generate RSS:
Copy code The code is as follows:
/**
** PHP dynamically generates RSS classes
**/
define("TIME_ZONE","");
define("FEEDCREATOR_VERSION","www.jb51.net");//您的网址
class FeedItem extends HtmlDescribable{
var $title,$description,$link;
var $author,$authorEmail,$image,$category,$comments,$guid,$source,$creator;
var $date;
var $additionalElements=Array();
}
class FeedImage extends HtmlDescribable{
var $title,$url,$link;
var $width,$height,$description;
}
class HtmlDescribable{
var $descriptionHtmlSyndicated;
var $descriptionTruncSize;
function getDescription(){
$descriptionField=new FeedHtmlField($this->description);
$descriptionField->syndicateHtml=$this->descriptionHtmlSyndicated;
$descriptionField->truncSize=$this->descriptionTruncSize;
return $descriptionField->output();
}
}
class FeedHtmlField{
var $rawFieldContent;
var $truncSize,$syndicateHtml;
function FeedHtmlField($parFieldContent){
if($parFieldContent){
$this->rawFieldContent=$parFieldContent;
}
}
function output(){
if(!$this->rawFieldContent){
$result="";
} elseif($this->syndicateHtml){
$result="rawFieldContent."]]>";
}else{
if($this->truncSize and is_int($this->truncSize)){
$result=FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent),$this->truncSize);
}else{
$result=htmlspecialchars($this->rawFieldContent);
}
}
return $result;
}
}
class UniversalFeedCreator extends FeedCreator{
var $_feed;
function _setFormat($format){
switch (strtoupper($format)){
case "2.0":
// fall through
case "RSS2.0":
$this->_feed=new RSSCreator20();
break;
case "0.91":
// fall through
case "RSS0.91":
$this->_feed=new RSSCreator091();
break;
default:
$this->_feed=new RSSCreator091();
break;
}
$vars=get_object_vars($this); foreach ($vars as $key => $value){
// prevent overwriting of properties "contentType","encoding"; do not copy "_feed" itself
if(!in_array($key, array("_feed","contentType","encoding"))){
$this->_feed->{$key}=$this->{$key};
}
}
}
function createFeed($format="RSS0.91"){
$this->_setFormat($format);
return $this->_feed->createFeed();
}
function saveFeed($format="RSS0.91",$filename="",$displayContents=true){
$this->_setFormat($format);
$this->_feed->saveFeed($filename,$displayContents);
}
function useCached($format="RSS0.91",$filename="",$timeout=3600){
$this->_setFormat($format);
$this->_feed->useCached($filename,$timeout);
}
}
class FeedCreator extends HtmlDescribable{
var $title,$description,$link;
var $syndicationURL,$image,$language,$copyright,$pubDate,$lastBuildDate,$editor,$editorEmail,$webmaster,$category,$docs,$ttl,$rating,$skipHours,$skipDays;
var $xslStyleSheet="";
var $items=Array();
var $contentType="application/xml";
var $encoding="utf-8";
var $additionalElements=Array();
function addItem($item){
$this->items[]=$item;
}
function clearItem2Null(){
$this->items=array();
}
function iTrunc($string,$length){
if(strlen($string)<=$length){
return $string;
}
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/958257.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/958257.htmlTechArticleHow to generate RSS subscriptions in php, phprss subscription This article describes how to generate RSS subscriptions in php. Share it with everyone for your reference. The specific analysis is as follows: RSS (Simple Information Syndication, also called...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn