note 77819 deleted from function.dom-domdocument-savehtmlfile by felipe

From: Date: Mon, 24 Dec 2007 02:36:39 +0000
Subject: note 77819 deleted from function.dom-domdocument-savehtmlfile by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133954@lists.php.net to get a copy of this message
Note Submitter: dev at asp55-ns dot com ---- So one thing I've noticed is that DOMDocument->saveHTMLFile() does not create W3C valid HTML. <br> and <img> nodes aren't closed, leading to errors if you want to validate it. To fix this, I've created a simple function. <?php function valid_saveHTMLFile($in,$outputFile) { $in = preg_replace('/<br(.*?)\/?>/','<br$1/>',$in); $in = preg_replace('/<img(.*?)\/?>/','<img$1/>',$in); return file_put_contents($outputFile,$in); } ?> to call it <?php valid_saveHTMLFile($dom->saveHTML(),'pathtofile'); ?> with $dom being your DOMDocument, and 'pathtofile' being...here's a surprise...the path to your save file. The function returns the exact same thing file_put_contents returns (ie: The function returns the amount of bytes that were written to the file, or FALSE on failure.)

« previous php.notes (#133954) next »