Created
February 22, 2012 21:44
-
-
Save zircote/1887612 to your computer and use it in GitHub Desktop.
Enables CDATA tags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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