$text = '<p width="50px;" style="padding:0px;"><strong style="padding:0;margin:0;">hello</strong></p><table style="text-align:center"></table>';
$text_2 = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $text);
OUTPUT(i have given the html format here):
<p>
<strong>hello</strong>
</p>
<table></table>
My problem is all attributes must be removed but not the attributes belongs to table. That is i am expecting the out put exactly like below(HTML FORMAT):
<p>
<strong>hello</strong>
</p>
<table style="text-align:center"></table>
What should i need to modify in the above regular expression to achieve it..
Any help will be thankful and grateful….
Thanks in advance…
You are very close with your current reg-ex. You need to do a check (think it is a negative look-ahead in this case?)
<(?!table)([a-z][a-z0-9]*)[^>]*?(\/?)>What that first bit of reg-ex is doing is checking that it does not start with ‘table’, then it is your regex.