- var_dump: documentation ( source)
<?php
function getColor($domnode) {
while($domnode->parentNode) {
if ($domnode->parentNode->getAttribute('color')) {
return $domnode->parentNode->getAttribute('color');
}
}
}
$html = '<FONT FACE="League" SIZE="15" COLOR="#000000"><font COLOR="#ff00ff" SIZE="18"><b><font SIZE="23"><font SIZE="27"><font SIZE="23"><font SIZE="18"><font SIZE="23">Moet Flip make-up dragen? <br />Stem mee in de poll!!</font></font></font></font></font></b></font><br /></FONT>';
$dom = new DOMDOcument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$nodes = $xpath->evaluate("/html/body//text()");
foreach ($nodes as $node) {
$color = getColor($node);
var_dump($color);
if ($color) {
$span = $document->createElement('span');
$span->setAttribute('style', 'color: ' . $color . ';');
var_dump($node);
$node->parentNode->replaceChild($span, $node);
}
}
var_dump($dom->saveHTML());