<?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());
- Output for 5.3.7 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Process exited with code 137.
preferences:
174.89 ms | 404 KiB | 252 Q