good evening dear Community, 8)
Well first of all: felize Navidad - I wanna wish you a Merry
Christmas!!
Today i'm trying to debug a little DOMDocument object in a PHP-parer.
Ideally it'd be nice if I could get DOMDocument to output in a array-
like format, to store the data in a database!
My example: head over to the target-url:
http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=8880
I investigated the Sourcecode:
I want to filter out the data that that is in the following class <div
class="floatbox">
See the sourcecode:
<span class="grey"> <span style="font-size:x-small;">></span></
span>
<a class="navLink" href="
http://dms-schule.bildung.hessen.de/suchen/
index.html" title="Suchformulare zum hessischen schulischen
Bildungssystem">suche</a>
</div>
</div>
<!-- begin of text -->
<h3>Siegfried-Pickert Schule</h3>
<div class="floatbox">
See my approach: Here is the solution return the labels and values in
a formatted array ready for input to mysql!
<?php
$dom = new DOMDocument();
@$dom->loadHTMLFile('
http://dms-schule.bildung.hessen.de/suchen/
suche_schul_db.html?show_school=8880');
$divElement = $dom->getElementById('floatbox');
$innerHTML= '';
$children = $divElement->childNodes;
foreach ($children as $child) {
$innerHTML = $child->ownerDocument->saveXML( $child );
$doc = new DOMDocument();
$doc->loadHTML($innerHTML);
//$divElementNew = $dom->getElementsByTagName('td');
$divElementNew = $dom->getElementsByTagname('td');
/*** the array to return ***/
$out = array();
foreach ($divElementNew as $item)
{
/*** add node value to the out array ***/
$out[] = $item->nodeValue;
}
echo '<pre>';
print_r($out);
echo '</pre>';
}
well Duhh: this outputs lot of garbage. The code spits out a lot of
html anyway.
What can i do to get a more cleaned up code!?
What is wrong with the idea of using this attribute:
$dom->getElementById('floatbox');
any idea!?
any and all help will greatly appreciated.
season-greetings
matze