note 92881 modified in class.domdocumentfragment by danbrown

From: Date: Thu, 13 Aug 2009 01:56:12 +0000
Subject: note 92881 modified in class.domdocumentfragment by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159422@lists.php.net to get a copy of this message
I found DOMDocument very useful for extracting raw XML from a field in a MySQL database. The following always gave me character entities for the XML tag brackets (&lt; &gt;) in the output (whether I used the utf8_encode function or htmlspecialchars function or neither of them on $row['text']): <?php $next_elem = $doc->createElement( $row['node_type'], utf8_encode($row['text']) ); $section_elem->appendChild($next_elem); ?> I changed the code to use a DOMDocumentFragment and now the XML I stored in my database comes out as XML in my output with proper tag brackets instead of html character entities: <?php $next_elem = $doc->createDocumentFragment(); $next_elem->appendXML($row['text']); $section_elem->appendChild($next_elem); ?> --was-- I found DOMDocument very useful for extracting raw XML from a field in a MySQL database. The following always gave me character entities for the XML tag brackets (&lt; &gt;) in the output (whether I used the utf8_encode function or htmlspecialchars function or neither of them on $row['text']): $next_elem = $doc->createElement( $row['node_type'], utf8_encode($row['text']) ); $section_elem->appendChild($next_elem); I changed the code to use a DOMDocumentFragment and now the XML I stored in my database comes out as XML in my output with proper tag brackets instead of html character entities: $next_elem = $doc->createDocumentFragment(); $next_elem->appendXML($row['text']); $section_elem->appendChild($next_elem); http://php.net/manual/en/class.domdocumentfragment.php

« previous php.notes (#159422) next »