regex - Removing excess ">" in string in PHP -
this question has answer here:
- remove style attribute html tags 7 answers
in code string have html tags so:
$string = '<div style="width:100px;">abc 1234 <span> test string, testing string</span></div>'; now, removed style attribute said string using preg_replace:
$string = preg_replace('/(<[^>]+) style=".*?"/i', '', $string); after removing style tag, managed remove style attribute div tag ended looking <div>. problem, encountered after doing excess > after closing tag span string looks now:
$string = '<div>abc 1234 <span> test string, testing string</span> > </div>'; my question is, why did exccess >? there different regular expression can use rid of style attribute without additional > appearing? or there way can ride of this?
i tried using str_replace twice so:
$string = str_replace("\n", "", $string); $string = str_replace(">>", ">", $string); but did not work either.
i not trying remove html tags, style part.
use string.
<?php $string = "<div style=\"width:100px;\">abc 1234 <span> test string, testing string</span></div>"; $string = strip_tags($string,"<span>"); $string = "<div>".$string."</div>"; ?> now string is:
<div>abc 1234 <span> test string, testing string</span></div>
Comments
Post a Comment