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 >&nbsp;</p> <p>&nbsp;</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;">&nbsp;</p> <p style="margin:0;">&nbsp;</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 >&nbsp;</p>\n<p>&nbsp;</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;

live demo


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -