沒辦法,近來靠php吃飯-_-
<?
/*************
|?+-------------------------------------------------
|?Id:??????????????????????????????
|?+-------------------------------------------------
|?Copyright?(c)?
|?Author:Howie
|?Email:?qywyh_scut@163.com
|?+-------------------------------------------------
|?Create?Date:?2007-2-3
|?Modify?Date:?
|?Note:??
|?demo:
|???$objRSS?=?new?loadRSS('http://news.163.com/special/00011K6L/rss_gn.xml',?10,?'cache/test.xml');
|???echo?$objRSS->getRSS();
|
|?+-------------------------------------------------
***************/
class?loadRSS?{
????
????//RSS?url鏈接
????var?$_url?=?'';

????//RSS?緩存目錄
????var?$_cacheDir?=?'';

????//緩存時間
????var?$_cacheTime?=?'';

????//是否從緩存讀取
????var?$_loadFromCache?=?true;

????//保存rss字符串
????var?$_str?=?'';

????function?loadRSS?($url,?$cacheTime=0,?$cacheDir=''){
????????$this->_url?=?$url;
????????if?($cacheDir?==?''?||?$cacheTime?==?0)?{
????????????$this->_loadFromCache?=?false;
????????}?else?{
????????????$this->_cacheTime?=?$cacheTime;
????????????$this->_cacheDir?=?$cacheDir;
????????}
????}

????function?getRSS?()?{
????????if?(!$this->_loadFromCache)?{
????????????$fp?=?fopen($this->_url,?'r');
????????????while?($tmp?=?fgets($fp,?4096))?{
????????????????$this->_str?.=?$tmp;
????????????}
????????????fclose($fp);
????????????//echo?$this->_str;
????????}?else?{
????????????$fileModifyTime?=?@filemtime($this->_cacheDir);
????????????$nowTime?=?time();
????????????//修改緩存文件
????????????if?(!$fileModifyTime?||?$nowTime-$fileModifyTime?>=?$this->_cacheTime)?{
????????????????$fp?=?fopen($this->_url,?'r');
????????????????$fp2?=?fopen($this->_cacheDir,?'w');
????????????????while?($tmp?=?fgets($fp,?4096))?{
????????????????????fwrite($fp2,?$tmp);
????????????????????$this->_str?.=?$tmp;
????????????????}
????????????????fclose($fp);
????????????????fclose($fp2);
????????????????return?$this->_str;
????????????}
????????????$fp?=?fopen($this->_cacheDir,?'r');
????????????while?($tmp?=?fgets($fp,?4096))?{
????????????????$this->_str?.=?$tmp;
????????????}
????????????fclose($fp);
????????}
????????return?$this->_str;
????}

}
?>
posted on 2007-02-03 01:32
豪 閱讀(360)
評論(0) 編輯 收藏 引用 所屬分類:
PHP之路