반응형
https://www.php.net/manual/en/book.xmlwriter.php
php로 rss를 만 들일이 생겨 사용하게 된 XMLWriter.
<?php
class RSS extends XMLWriter
{
function __construct()
{
$this->openURI('../rss.xml');
$this->startDocument('1.0');
$this->setIndent(4);
$this->startElement('rss');
$this->writeAttribute('version', '2.0');
$this->writeAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
$this->startElement("channel");
$this->writeElement('title', '');
$this->writeElement('link', '');
$this->writeElement('description', '');
$this->writeElement('language', '');
}
function addItems($a, $b, $c)
{
$this->startElement("item");
$this->startElement("title");
$this->writeCdata(htmlspecialchars_decode($b));
$this->endElement();
$this->startElement("content");
$this->writeCdata(htmlspecialchars_decode($c));
$this->endElement();
$this->writeElement("published", date("Y-m-d H:i:s"));
$this->writeElement("status", $a);
$this->writeElement("link", '');
$this->endElement();
$this->_endRss();
}
function _endRss()
{
// End channel
$this->endElement();
// End rss
$this->endElement();
$this->endDocument();
$this->flush();
}
?>
※ 참고 사이트 :
https://board.phpbuilder.com/d/10356853-a-quick-php-xmlwriter-class-tutorial-xml-amp-rss/2
반응형
'개발 > php' 카테고리의 다른 글
특정 버전의 Composer 설치 (0) | 2024.11.14 |
---|---|
[php] version switch (0) | 2023.05.16 |
[PHP] version update (ubuntu) (0) | 2023.01.26 |