I am interesting in removing everything in between and including the inline style 开发者_如何学Ctags from my output. for example:
style="height:10px;"
The issue I have been having is, I found some php replacement expressions that work, however they are also removing my paragraph tags and such.
Any help with this is appreciated. Thank you
Try:
$html = preg_replace('%style="[^"]+"%i', '', $html);
Use DOM Document to remove the attribute of the tags.
http://php.net/manual/en/class.domdocument.php
This should do it using DOM and a simple XPath query to find relevant elements:
<?
$doc = new DOMDocument();
$doc->loadHTML($html);
$search = new DOMXPath($doc);
$results = $search->evaluate('//*[@style]');
foreach ($results as &$result)
$result->removeAttribute('style');
$newhtml = $doc->saveHTML();
?>
精彩评论