Function:
function innerHTML($element) {
$pObject = new DOMDocument( '1.0', 'utf-8');
$pObject->appendChild( $pObject->importNode( $element, true ));
return $pObject->saveHTML();
}
Example:
$dom = new DomDocument('1.0', 'utf-8');
$dom->loadHTML($content);
$divs = $dom->getElementsByTagName('div');
$ndiv = $divs->length;
for ($i = 0; $i < $ndiv; $i++) {
$div = $divs->item($i);
if ($div->hasAttributes()) {
$attributes = $div->attributes;
foreach ($attributes as $j => $attribute) {
if ($attribue->name == 'class' && $attribute->value=='you-are-looking-for') {
$innerHTML = innerHTML($div);
}
}
}
}
Title:
Use DomDocument how to get innerHTML of element
Description:
Function: function innerHTML($element) { $pObject = new DOMDocument( '1.0', 'utf-8'); $pObject->appendChild( ...
...
Rating:
4