I suck at anything OO. I just never really caught on to it, or saw enough advantage in it to bother. I'm trying to play 'catch up' though and
learn
something new.
So for my '
learn
ing
experience' I thought I'd play around a bit with the
PHP
DOM stuff, and do some neat stuff with xpath. I can't figure it out though. If I'd have just stuck with fucntional code, and
regex
s I'd be done by now, but I wanna
learn
something today.

Here is my code to find the action of the forms on a page:
//Now find all the forms.
// parse the html into a DOMDocument
//ob_start(); //this generates a lot of errors, that dump the output file
$dom = new DOMDocument();
@$dom->loadHTML($page);
//ob_end_clean();
$xpath = new DOMXPath($dom);
$forms = $xpath->evaluate("/html/body//form");
for ($i = 0; $i < $forms->length; $i++) {
print "Finding form action.
";
$form = $forms->item($i);
$action = $form->getAttribute('action');
if (substr($action,0,

!= "https://"

{
if ( substr($action,0,7) == "http://" ) $action = $action;
elseif ( substr($action,0,1) == "/" ) $action = "http://$domain" . $action;
else $action = "http://$domain/" . $action;
}else $action = $action;
}
This code actually works, though it seems really ugly most of that ugly is my crappy 'relative to absolute URL' kludge. The problem is I can't figure out how to get more data about my form out. Like when I do '$action = $form->getAttribute('action');', isn't there some way I could do something like '$formstuff[] = $dom->getAllTheFishinElementsAndAttributesAndPutThemInANormalArrayYouBastard('*');' instead?
It keeps returning DOMNodeDingleberries instead of anything useful that I can just iterate through, and then for each DOMDingleberrie the only way I can see to get anything useful out of it is to already know the tag name or ID which I don't have.
I mean All I really want is to pull out all the forms, then return an array with all the various elements and their values and whatnot, but the way I'm seeing this is that I'm going to have to write something like the above hunk O' crap for every possible tag (input, option, yadadadad), and then parse each form.
What obvious crap am I missing? There has to be something, or
PHP
s DOM functionality is pretty damned pointless.
Also: XML makes the baby Jesus cry.