Jump to content

Domdocument, Loadhtml And Line Break Problem


MMDE

Recommended Posts

Heya

 

I use DOMDocument and loadHTML to run through some data of a HTML page.

 

My problem is that when I for example do this:

$trs = $site->getElementsByTagName('tr');
while($tr AS $tr){
$td = $tr->childNodes->item(0);
$newString = $td->nodeValue;
}

The string in the <td> can contain for example a br tag, and if that is the case, I would like to include it at it's correct position.

I know how to check if the td tag has a br tag, but I don't know how to apply it at it's correct position in the string $newString.

 

Anyone got any good ideas?

 

 

BTW, the post new editor is kinda bad for this type of a forum. I got no idea how to add tabbed spaces, and the title of the thread all of a sudden had capital letters at the beginning of each word and it has decapitilized the rest. I wanted it to be:

DOMDocument, loadHTML and line break problem

 

 

-

MMDE

I found a solution myself.

 


function getNodeInnerHTML($domn){
$domd = new DOMDocument();
if($domn->hasChildNodes()){
foreach($domn->childNodes as $domnc){
$domd->appendChild($domd->importNode($domnc, true));
}
}
return $domd->saveHTML();
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.