我有一个字符串,我想从中删除<style>
。
我正在尝试以下
$description = $product_info['description'];
$doc = new DOMDocument();
$doc->loadHTML($description);
$list = $doc->getElementsByTagName('style');
while($list->length >0) {
$p = $list->item(0);
$p->parentNode->removeChild($p);
}
echo $doc->saveHTML();
但它没有从输出中删除<style>
。
<style>.textleft{ margin-bottom:10px; float:left; display: inline-block; width:56%; text-align:left; padding-right:20px; padding-left:20px; } .textleft > p { display: table-cell; height: 150px; vertical-align: middle; } .imageblock{ display:inline-block; margin-bottom:10px; width: 44%; } .textright{ margin-bottom:10px; float:right; display: inline-block; width:56%; text-align:left; padding-left:20px; padding-right:20px; } .containerz{ display:block; } .featimage{ vertical-align:middle; display:inline-block; width:53%; max-height:245px; } .features{ vertical-align:middle; display:inline-block; width:46%; padding-left:30px; } .textright > p { display: table-cell; height: 150px; vertical-align: middle; } @media screen and (max-width: 991px) { .textleft, .textright, .imageblock{ width:100%; float:none; padding-left: 0px; padding-right: 0px; } /*.imageblock > img { width:100%;}*/ .containerz {text-align:center;} .textright > p, .textleft > p { height: 100%; } .textright, .textleft { margin-bottom: 0px; } .features, .featimage { padding-left: 0px; width:100%; float:none;} .features { padding-top: 10px;} .imageblock {margin-bottom: 25px;} } </style> <h1><strong>WhiteCoat Clipboard<sup>®</sup> - TEAL - Vertical Metric Medical Edition</strong></h1>
或者是否有其他方法可以删除<style>
及其内容?