note 95252 added to domdocument.savexml

From: Date: Mon, 21 Dec 2009 17:21:36 +0000
Subject: note 95252 added to domdocument.savexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-164241@lists.php.net to get a copy of this message
If you use saveXML($node) to save a part of an HTML document, you may want to use this function to make empty tags more HTML-compatible: <?php function xml2xhtml($xml) { return preg_replace_callback('#<(\w+)([^>]*)\s*/>#s', create_function('$m', ' $xhtml_tags = array("br", "hr", "input", "frame", "img", "area", "link", "col", "base", "basefont", "param"); return in_array($m[1], $xhtml_tags) ? "<$m[1]$m[2] />" : "<$m[1]$m[2]></$m[1]>"; '), $xml); } ?> example: <?php $doc = new DOMDocument(); $doc->loadHTML('<div class="clear"></div><br><p></p>'); $output = $doc->saveXML($doc->documentElement); echo $output; // output: <html><body><div class="clear"/><br/><p/></body></html> echo xml2xhtml($output); // output: <html><body><div class="clear"></div><br /><p></p></body></html> ?> ---- Server IP: 193.219.81.76 Probable Submitter: 88.119.136.57 ---- Manual Page -- http://www.php.net/manual/en/domdocument.savexml.php Edit -- https://master.php.net/note/edit/95252 Del: integrated -- https://master.php.net/note/delete/95252/integrated Del: useless -- https://master.php.net/note/delete/95252/useless Del: bad code -- https://master.php.net/note/delete/95252/bad+code Del: spam -- https://master.php.net/note/delete/95252/spam Del: non-english -- https://master.php.net/note/delete/95252/non-english Del: in docs -- https://master.php.net/note/delete/95252/in+docs Del: other reasons-- https://master.php.net/note/delete/95252 Reject -- https://master.php.net/note/reject/95252 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164241) next »