note 90853 added to domdocument.savehtml

From: Date: Wed, 13 May 2009 02:35:54 +0000
Subject: note 90853 added to domdocument.savehtml
Groups: php.notes 
Request: Send a blank email to php-notes+get-154531@lists.php.net to get a copy of this message
To avoid script tags from being output as <script />, you can use the DOMDocumentFragment class: <?php $doc = new DOMDocument(); $doc -> loadXML($xmlstring); $fragment = $doc->createDocumentFragment(); /* Append the script element to the fragment using raw XML strings (will be preserved in their raw form) and if succesful proceed to insert it in the DOM tree */ if($fragment->appendXML("<script type='text/javascript' src='$source'></script>") { $xpath = new DOMXpath($doc); $resultlist = $xpath->query("//*[local-name() = 'html']/*[local-name() = 'head']"); /* namespace-safe method to find all head elements which are childs of the html element, should only return 1 match */ foreach($resultlist as $headnode) // insert the script tag $headnode->appendChild($fragment); } $doc->saveXML(); /* and our script tags will still be <script></script> */ ?> ---- Server IP: 213.249.64.162 Probable Submitter: 86.88.83.116 ---- Manual Page -- http://www.php.net/manual/en/domdocument.savehtml.php Edit -- https://master.php.net/note/edit/90853 Del: integrated -- https://master.php.net/note/delete/90853/integrated Del: useless -- https://master.php.net/note/delete/90853/useless Del: bad code -- https://master.php.net/note/delete/90853/bad+code Del: spam -- https://master.php.net/note/delete/90853/spam Del: non-english -- https://master.php.net/note/delete/90853/non-english Del: in docs -- https://master.php.net/note/delete/90853/in+docs Del: other reasons-- https://master.php.net/note/delete/90853 Reject -- https://master.php.net/note/reject/90853 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154531) next »