saveHTML() on DOMDocument returns inconvenient HTML-source

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
UltimateWeapon
Forum Newbie
Posts: 2
Joined: Mon Jan 17, 2011 5:55 am

saveHTML() on DOMDocument returns inconvenient HTML-source

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: saveHTML() on DOMDocument returns inconvenient HTML-sour

Post 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();
UltimateWeapon
Forum Newbie
Posts: 2
Joined: Mon Jan 17, 2011 5:55 am

Re: saveHTML() on DOMDocument returns inconvenient HTML-sour

Post by UltimateWeapon »

thank you !! :D
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: saveHTML() on DOMDocument returns inconvenient HTML-sour

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: saveHTML() on DOMDocument returns inconvenient HTML-sour

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: saveHTML() on DOMDocument returns inconvenient HTML-sour

Post by Weirdan »

John Cartwright wrote: DOM - Domain Object Model - See definition, or see the manual
DOM = Document Object Model, and that's not the same as your wikipedia link.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: saveHTML() on DOMDocument returns inconvenient HTML-sour

Post by John Cartwright »

Oops. That's what I get for posting before my 4th coffee of the morning. :D
Post Reply