note 77819 added to function.dom-domdocument-savehtmlfile

From: Date: Thu, 13 Sep 2007 23:26:57 +0000
Subject: note 77819 added to function.dom-domdocument-savehtmlfile
Groups: php.notes 
Request: Send a blank email to php-notes+get-130486@lists.php.net to get a copy of this message
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.) ---- Server IP: 209.41.74.194 Probable Submitter: 63.164.145.198 ---- Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-savehtmlfile.php Edit -- https://master.php.net/note/edit/77819 Del: integrated -- https://master.php.net/note/delete/77819/integrated Del: useless -- https://master.php.net/note/delete/77819/useless Del: bad code -- https://master.php.net/note/delete/77819/bad+code Del: spam -- https://master.php.net/note/delete/77819/spam Del: non-english -- https://master.php.net/note/delete/77819/non-english Del: in docs -- https://master.php.net/note/delete/77819/in+docs Del: other reasons-- https://master.php.net/note/delete/77819 Reject -- https://master.php.net/note/reject/77819 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130486) next »