php - how to replace and add style into specific tag -
i have problem. can't replace , add inline style css. have input:
<p style="text-align: justify;"><span style="font-size: 11pt;">hello world<br /></span></p> <p id="tem" style="text-align: justify;">test</p> <p > </p> <p> </p>
and want output:
<p style="text-align: justify;margin:0;"><span style="font-size: 11pt;">hello world<br /></span></p> <p id="tem" style="text-align: justify;margin:0;">test</p> <p style="margin:0;"> </p> <p style="margin:0;"> </p>
i have tried way demo
$re = "/(<p[^>]+\")([^>\"]+)/miu"; $str = "<p id=\"tem\" style=\"text-align: justify;\"><span style=\"font-size: 11pt;\">hello world<br /></span></p>\n<p style=\"text-align: justify;\">test</p>\n<p > </p>\n<p> </p>"; $subst = "$1$2margin:0;"; $result = preg_replace($re, $subst, $str);
please me anybody. thanks.
i have solved that:
search regex pattern ((?<=\<)[^>]+style=")([^>"]+)
, replace $1$2margin:0;
Comments
Post a Comment