I have a string likestring(8234) "<style>.{ margin-bottom:10px; float:left; display: inline-block; width:56%; text-align:left; padding-right:20px; padding-left:20px; } . > p { display: table-cell; height: 150px; vertical-align: middle; }..................</style>.................
I want to remove <style>
tag and all its contents.
I have tried
$description = $product_info['description']; // the string with style tag
$text = preg_replace('/<\s*style.+?<\s*\/\s*style.*?>/si', ' ', $description );
echo $text;
but it shows the same string without removing <style>
tag.
I have also tried to replace only <style>
tag by doing
$text = str_replace("<style>", "", $description);
but this also doesn't work at all. I am seeing the same string again and again. I have also tried it with DOMParser
$doc = new DOMDocument();
$doc->loadHTML($description);
$xpath = new DOMXPath($doc);
foreach ($xpath->query('//style') as $node) {
$node->parentNode->removeChild($node);
}
$text = $doc->saveHTML();
but in all cases, output is the same with <style>
and its contents