본문 바로가기

개발/php

[PHP] XMLWriter

반응형

https://www.php.net/manual/en/book.xmlwriter.php

 

PHP: XMLWriter - Manual

The single quote predefined entity is not escaped.The other predefined entities are but not the single quote, so you will have to do it yourself.That's what you would expect:Ampersand     &     &Single Quote     '     'Double Quote     " 

www.php.net

 

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

 

A quick PHP XMLWriter Class Tutorial (XML & RSS)

Since there is absolutely no documentation on how to use PHP5's XMLWriter class, here is a very simple example of how to use the class to create an rss feed....

board.phpbuilder.com

 

반응형

'개발 > php' 카테고리의 다른 글

특정 버전의 Composer 설치  (0) 2024.11.14
[php] version switch  (0) 2023.05.16
[PHP] version update (ubuntu)  (0) 2023.01.26