Skip to content

Instantly share code, notes, and snippets.

@zircote
Created February 22, 2012 21:44
Show Gist options
  • Select an option

  • Save zircote/1887612 to your computer and use it in GitHub Desktop.

Select an option

Save zircote/1887612 to your computer and use it in GitHub Desktop.
Enables CDATA tags.
<?php
/**
*
*
* @author Robert Allen <zircote@gmail.com>
* @package Zircote
* @subpackage SimpleXMLElement
*
*
*/
class Zircote_SimpleXMLElement extends SimpleXMLElement
{
/**
* <code>
* $xml = new Zircote_SimpleXMLElement('<root></root>');
* $xml->addChild('childElement')
* ->addCData(base64_encode(sha1(time())));
* echo $xml->asXML();
* <?xml version="1.0"?>
* <root><childElement><![CDATA[YzhkMjNmNTU3YTgzOTBmN2ExZjI0ZmYxYjU3ODU2MmVjNDU1MjBkNw==]]></childElement></root>
* </code>
*
* @param string $cdata
* @return Zircote_SimpleXMLElement
*/
public function addCData ($cdata)
{
$node = dom_import_simplexml($this);
$node->appendChild($node->ownerDocument->createCDATASection($cdata));
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment