, Regex . Regex , . <foo> , >foo<, . .
DOM :
$html = <<< HTML
<img src="" style="display:none" />
<IMG src="" style="width:11px;display: none" >
<img src="" style="width:11px" >
HTML;
() . DOM :
$dom = new DOMDocument();
$dom->loadHtml($html);
$dom->normalizeDocument();
DOM "IMG", "style", "display". "display: none" XPath, :
$xpath = new DOMXPath($dom);
foreach($xpath->query('//img[contains(@style, "display")]') as $node) {
$style = str_replace(' ', '', $node->getAttribute('style'));
if(strpos($style, 'display:none') !== FALSE) {
$node->parentNode->removeChild($node);
}
}
IMG . , "display: none", , DOM.
HTML:
echo $dom->saveHTML();
:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><img src="" style="width:11px"></body></html>
Regex!
: XML- CSS