PHP는 RSS 파일 클래스 example_php 기술을 생성합니다.

WBOY
풀어 주다: 2016-05-16 20:28:46
원래의
1061명이 탐색했습니다.

이 기사의 예에서는 PHP로 RSS 파일을 생성하는 방법을 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 세부 내용은 다음과 같습니다.

PHP RSS 생성 클래스 예제 코드는 다음과 같습니다.

코드 복사 코드는 다음과 같습니다.
if (defined('_class_rss_php')) return;
정의('_class_rss_php教程',1);
/**
 
 *  使用说明:
 *  $rss = new rss('redfox','http://jb51.net/',"redfox의 블로그");
 *  $rss->additem('rss class',"http://www.jb51.net","xxx",date());
 *  $rss->항목 추가(...);
 *  $rss->파일에 저장(...);
 */
 
클래스 RSS {
   //공개
   $rss_ver = "2.0";
   $channel_title = '';
   $channel_link = '';
   $channel_description = '';
   $언어 = 'zh_cn';
   $저작권 = '';
   $웹마스터 = '';
   $pubdate = '';
   $lastbuilddate = '';
   $generator = 'redfox RSS 생성기';
 
   $content = '';
   $items = 배열();
 
   함수 rss($title, $link, $description) {
       $this->channel_title = $title;
       $this->channel_link = $link;
       $this->channel_description = $설명;
       $this->pubdate = date('y-m-d h:i:s',time());
       $this->lastbuilddate = date('y-m-d h:i:s',time());
   }
 
   함수 additem($title, $link, $description ,$pubdate) {
       $this->items[] = array('titile' => $title ,
                        '링크' => $링크,
                        '설명' => $설명,
                        '게시물' => $pubdate);
   }
 
   함수 buildrss() {
       $s = " ";
       // 채널 시작
       $s .= " ";
       $s .= " "
       $s .= "<링크 />{$this->채널_링크} ";
       $s .= "{$this->channel_description} ";
       $s .= "{$this->언어} ";
       if (!emptyempty($this->copyright)) {
          $s .= "{$this->저작권} ";
       }
       if (!emptyempty($this->webmaster)) {
          $s .= "{$this->웹마스터} ";
       }
       if (!emptyempty($this->pubdate)) {
          $s .= "{$this->pubdate} ";
       }
 
       if (!emptyempty($this->lastbuilddate)) {
          $s .= "{$this->lastbuilddate} ";
       }
 
       if (!emptyempty($this->generator)) {
          $s .= "{$this->발전기} ";
       }
      
       // 항목 시작
       for ($i=0;$iites),$i ) {
           $s .= " ";
           $s .= " ";
           $s .= "<링크 />{$this->항목[$i]['link']} ";
           $s .= "항목[$i]['description']}]]> ";
           $s .= "{$this->items[$i]['pubdate']} ";          
               $s .= " "
         }
       
// 채널 닫기
$s .= " "
$this->content = $s; }

함수 표시() {
If (emptyempty($this->content)) $this->buildrss()
헤더('콘텐츠 유형:텍스트/xml')
echo($this->content)
}

함수 savetofile($fname) {
If (emptyempty($this->content)) $this->buildrss()
         $handle = fopen($fname, 'wb')
($handle === false)인 경우 false를 반환합니다.
fwrite($handle, $this->content)
         fclose($handle)
}
}
?>
이 기사가 모든 사람의 PHP 프로그래밍 설계에 도움이 되기를 바랍니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!