<?php /** * Adds a CDATA property to an XML document. * * @param string $name * Name of property that should contain CDATA. * @param string $value * Value that should be inserted into a CDATA child. * @param object $parent * Element that the CDATA child should be attached too. */ $add_cdata = function($name, $value, &$parent) { $child = $parent->addChild($name); if ($child !== NULL) { $child_node = dom_import_simplexml($child); $child_owner = $child_node->ownerDocument; $child_node->appendChild($child_owner->createCDATASection($value)); } return $child; }; $parent = new SimpleXMLElement('<?xml version="1.0"?><ITEM />'); $child = $add_cdata('name', 'DELL S2721DGFA 68,5cm (27") WQHD IPS', $parent); echo $parent->asXML(), "\n"; echo $child->asXML(), "\n";
You have javascript disabled. You will not be able to edit any code.