PHP DOM Inspector

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
MasterArtist
Forum Newbie
Posts: 3
Joined: Fri Sep 28, 2007 5:53 am

PHP DOM Inspector

Post by MasterArtist »

Hi all,

Im doing some coding where I'm loading an HTML document into a DOM as follows:

$dom = new DOMDocument();
$dom->loadHTMLFile($source);


However its difficult to parse the created $dom because I dont have an idea of its structure, especially with HTML documents that are not well-formed.

Is there example code/program that will display the DOM generated (similar to the Firefox DOM inspector), so I know what kind of structure has been created?

Thanks
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

You can do print_r() on the object or do $dom->dump_mem() and view the source. THat might give you an idea of what the hodge-podge of HTML got turned into.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You should know *what* you want to do with the document before you try to do anything to it. I can't think of many situations where you'd need to somehow have the whole structure laid out to you before you do anything, especially since the application won't work based on wisdom and intuition.
MasterArtist
Forum Newbie
Posts: 3
Joined: Fri Sep 28, 2007 5:53 am

Post by MasterArtist »

You should know *what* you want to do with the document before you try to do anything to it.
I know *what* I want to do with the document, but in order to do *what* I want I need to know *how* the document has been structured...
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

you can try Begby's procedure and find out "how"...
Post Reply