|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-05-10 21:00 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
Description: ------------ If you create an element on a DOMDocument, and then append a CDATA section to the node, if formatOutput is enabled, it makes the node put a return caridge before and after the CDATA section. IE: <key_0> <![CDATA[BLAHBLAH]]> </key_0> This is problematic, as when you fetch the data from the node, it carries the return caridges with it. The only way of solving this currently (that I know of) is to not use formattput on the DOMDocument. Reproduce code: --------------- <?php $dom = new DOMDocument("1.0"); $dom->formatOutput = true; $node = $dom->createElement("node"); $cdata = $dom->createCDATASection("BLAH BLAH BLAH"); $dom->appendChild($node); $node->appendChild($cdata); $dom2 = DOMDocument::loadXML($dom->saveXML()); $rootNode = $dom2->documentElement; $text = $rootNode->textContent; print("'$text'"); $packData = @unpack("H*", $text); print_r($packData); ?> Expected result: ---------------- 'BLAH BLAH BLAH'Array ( [1] => 424c414820424c414820424c4148 ) Actual result: -------------- ' BLAH BLAH BLAH 'Array ( [1] => 0a424c414820424c414820424c41480a ) //you can see the 0A after the ' and before the closing '