• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

一个完全面向对象的RSS/XML php类

PHP 水墨上仙 2294次浏览

一个完全面向对象的RSS/XML php类

<?php
error_reporting(E_ALL);
 
mysql_connect("localhost","root","root") or die (mysql_error());
mysql_select_db("oop") or die (mysql_error());
 
class RSS {
 
var $XMLdump;
 
var $pagetitle;
var $pagelink;
var $pegedescription;
var $pagelanguage;
 
var $sqlresult;
 
function setHead($setPagetitle, $setPagelink, $setPegedescription, $setPagelanguage){
	$this->pagetitle = $setPagetitle;
	$this->pagelink = $setPagelink;
	$this->pegedescription = $setPegedescription;
	$this->pagelanguage = $setPagelanguage;
}
 
function getDataFrom($setSQL){
	$this->sqlresult = mysql_query($setSQL);
}
 
 
function rssHead(){
	$this->XMLdump = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom/\">
	<channel>
		<title>".$this->pagetitle."</title>
		<link>".$this->pagelink."</link>
		<description>".$this->pegedescription."</description>
		<language>".$this->pagelanguage."</language>
		<lastBuildDate>".date("r", time())."</lastBuildDate>\n";
}
 
function rssItems(){
	while($bla = mysql_fetch_assoc($this->sqlresult)){
		$this->XMLdump .= "		<item>\n";
		$this->XMLdump .= "			<title>".$bla['title']."</title>\n";
		$this->XMLdump .= "			<link>http://bestnewssiteever.com/news/".$bla['id']."/</link>\n";
		$this->XMLdump .= "			<category>".$bla['category']."</category>\n";
		$this->XMLdump .= "			<pubDate>".date("r",$bla['pubDate'])."</pubDate>\n";
		preg_match_all("/^(?:[^.]*\.){3}/", $bla['content'], $trimedContent);
		$this->XMLdump .= "			<description>".$trimedContent[0][0]."..</description>\n";
		$this->XMLdump .= "		</item>\n";
	}
}
 
function rssFooter(){
	$this->XMLdump .= " 	</channel>
</rss>";
}
 
function writeXML(){
	$this->rssHead();
	$this->rssItems();
	$this->rssFooter();
	return $this->XMLdump;
}
 
function saveXML($file){
	$fp = fopen($file,"w+");
	flock($fp,2);
	fwrite($fp,$this->writeXML());
	flock($fp,3);
	fclose($fp);
}
}
 
$Bar = new RSS();
$Bar->getDataFrom("SELECT * FROM news ORDER BY pubDate DESC");
$Bar->setHead("TITLE","http://domain.de","DESCRIPTION","en-EN");
$Bar->saveXML("blub.xml");
 
?>


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明一个完全面向对象的RSS/XML php类
喜欢 (0)
加载中……