Page 1 of 1
saveHTML() on DOMDocument returns inconvenient HTML-source
Posted: Mon Jan 17, 2011 6:06 am
by UltimateWeapon
I use the following code:
Code: Select all
$doc = new DOMDocument();
$doc->loadHTMLFile('index.tpl.php');
/* do some DOM stuff with it */
...
echo $doc->saveHTML();
When I run the page in my browser, it shows all the HTML after eachother in the Page Source, like:
<html><head><title></title></head><body>....</body></html>
This is very inconvenient when I have to debug my HTML-source, does anyone know how I can get it to output it in a "normal" way,
where each tag is on a new line?
Re: saveHTML() on DOMDocument returns inconvenient HTML-sour
Posted: Mon Jan 17, 2011 10:09 am
by Weirdan
http://us2.php.net/domdocument#domdocum ... rmatoutput
Code: Select all
$doc = new DOMDocument();
$doc->formatOutput = true;
$doc->loadHTMLFile('index.tpl.php');
/* do some DOM stuff with it */
...
echo $doc->saveHTML();
Re: saveHTML() on DOMDocument returns inconvenient HTML-sour
Posted: Wed Jan 26, 2011 11:48 am
by UltimateWeapon
thank you !!

Re: saveHTML() on DOMDocument returns inconvenient HTML-sour
Posted: Wed Jan 26, 2011 1:08 pm
by danwguy
Ok, I am sorry for adding to this thread but I am very curious, what is a DOM document, and what do you mean by do DOM stuff here? sorry again, I am just very curious and would like to learn as much as possible. Also what does this code do exactly? grab a file and include it in another file? Wouldn't <?php include(file) ?> be an easier method? please don't make too much fun, I am trying to learn. Thank you.
Re: saveHTML() on DOMDocument returns inconvenient HTML-sour
Posted: Wed Jan 26, 2011 1:14 pm
by John Cartwright
danwguy wrote:Ok, I am sorry for adding to this thread but I am very curious, what is a DOM document, and what do you mean by do DOM stuff here? sorry again, I am just very curious and would like to learn as much as possible. Also what does this code do exactly? grab a file and include it in another file? Wouldn't <?php include(file) ?> be an easier method? please don't make too much fun, I am trying to learn. Thank you.
Please don't threadjack. If you have a question please feel free to create your own thread and reference this as needed.
DOM - Domain Object Model - See
definition, or see
the manual
Re: saveHTML() on DOMDocument returns inconvenient HTML-sour
Posted: Wed Jan 26, 2011 2:39 pm
by Weirdan
DOM =
Document Object Model, and that's not the same as your wikipedia link.
Re: saveHTML() on DOMDocument returns inconvenient HTML-sour
Posted: Wed Jan 26, 2011 2:45 pm
by John Cartwright
Oops. That's what I get for posting before my 4th coffee of the morning.
