xref: /PHP-7.4/ext/xmlwriter/tests/OO_012.phpt (revision cf0dd817)
1--TEST--
2XMLWriter: libxml2 XML Writer, Write CDATA
3--CREDITS--
4Mark Baker mark@lange.demon.co.uk at the PHPNW2017 Conference for PHP Testfest 2017
5--SKIPIF--
6<?php if (!extension_loaded("xmlwriter")) print "skip"; ?>
7--FILE--
8<?php
9
10$cDataString = "Text for inclusion within CData tags can include characters like <, >, &, and quotes like ' and \"";
11$xmlWriter = new XmlWriter();
12$xmlWriter->openMemory();
13
14$xmlWriter->startDocument('1.0', 'UTF-8');
15$xmlWriter->startElement('myDocumentRoot');
16$xmlWriter->startElement('myElement');
17// CData output
18$xmlWriter->startElement('cdataElement');
19$xmlWriter->writeCData($cDataString);
20$xmlWriter->endElement();
21// end the document and output
22$xmlWriter->endElement();
23$xmlWriter->endElement();
24
25echo $xmlWriter->outputMemory(true);
26
27?>
28--EXPECT--
29<?xml version="1.0" encoding="UTF-8"?>
30<myDocumentRoot><myElement><cdataElement><![CDATA[Text for inclusion within CData tags can include characters like <, >, &, and quotes like ' and "]]></cdataElement></myElement></myDocumentRoot>
31