I am only a few months into PHP and don't grasp all the things that i guess the "expert" programmers do, so for that i'm sorry... i'm working on it.
I need help with what code would accomplish what i need below, I have had only partial success but am now stuck.
I have used CURL to post to a remote site form and return the results, the returned results is the full raw HTML of that forms results page. There is only 1
table of data i need from the entire page and the only unique identifier of the table is a unique CLASS attribute. I have been able, through trial and error
to get the initial stage of assigning the HTML response to a PHP DOM object and identify the needed table by its class assignment using an example found on
the net. But: 1.) I really am having a hard time understand the whole DOM object models and manipulation. 2.) The code below, returns the TABLE i need, but all
HTML is stripped form it, thus i just get one long running line of text. I need that table and its content, html tags and all assigned to a variable. Please help.
Example:
^^^^^^ Lots of misc HTML code above ^^^^^^
<table class="magicname" height=100 width=100>
<tr>
<td> <p>whatever content is in here </p> </td>
</tr>
<tr>
<td> <p>whatever content is in here </p> </td>
</tr>
</table>
vvvvv Lots of misc HTML code below vvvv
My Current code:
$classname = 'maintbl';
$dom = new DOMDocument;
$dom->loadHTML($server_output);
$xpath = new DOMXPath($dom);
$results = $xpath->query("//*[@class='" . $classname . "']");
foreach($results as $node) {
echo "{$node->nodeName} - {$node->nodeValue}<br>";
// or you can just print out the the XML:
// $dom->saveXML($node);