(PHP 5 >= 5.1.2, PECL xmlwriter >= 0.1.0)

XMLWriter::writeCData -- xmlwriter_write_cdataWrite full CDATA tag


Stil obiect-orientat

bool XMLWriter::writeCData ( string $content )

Stil procedural

bool xmlwriter_write_cdata ( resource $xmlwriter , string $content )

Writes a full CDATA.



Numai pentru apelurile procedurale. Resursa XMLWriter care este modificată. Această resursă se obține în urma apelării xmlwriter_open_uri() sau xmlwriter_open_memory ().


The contents of the CDATA.

Valorile întoarse

Întoarce valoarea TRUE în cazul succesului sau FALSE în cazul eșecului.

A se vedea și

add a note add a note

User Contributed Notes 3 notes

t dot w dot natt at UNIVERSITY dot bath dot ac dot uk
7 years ago
Seen a couple of bug reports and gotchas with this one but not a simple code example. Just in case someone finds it useful:


// serve xml doc as xml
header('Content-type: application/xml');

// set up the document
$xml = new XmlWriter();
$xml->startDocument('1.0', 'UTF-8');

// CData output
$xml->writeCData("text for inclusion within CData tags");

// end the document and output

<?xml version="1.0" encoding="UTF-8"?>
        <mycdataelement><![CDATA[text for inclusion within CData tags]]>
dave at dtracorp dot com
8 years ago
i don't know if this is a bug with the underlying c code or not, or this is by design (i'm not a big xml guy), but for me, running on fedora core 5, php 5.2.1
to get this to work, the cdata functions need to wrap the description (or whatever element the cdata should appear in)
for example.
// initiate xmlwriter object as $xw
// add header, titles, etc.

// start cdata
// start description
// write cdata
$xw->writeCData('<img src="http://php.net/images/php.gif" />');
// write the description contents
$xw->text('php logo');
// end the description element
// end the cdata

// end xml, and output

otherwise, i just got warnings about writing cdata in the wrong context, and no cdata would be written
thesoupdragon at hotmail dot com
8 years ago
A rather strange effect with this.

UTF8 Mysql database

    $xml->writeCData( $tablecolor2 );

does not work !

    $tablecolor2 = utf8_decode ( $val['pcolor2']);
    $xml->writeCData( utf8_encode ($tablecolor2) );

cannot explain this - but it may help someone
To Top