I have this html code:
<p style="padding:0px;">
<strong style="padding:0;margin:0;">hello</strong>
</p>
How can I remove attributes from all tags? I’d like it to look like this:
<p>
<strong>hello</strong>
</p>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Adapted from my answer on a similar question
The RegExp broken down:
Add some quoting, and use the replacement text
<$1$2>it should strip any text after the tagname until the end of tag/>or just>.Please Note This isn’t necessarily going to work on ALL input, as the Anti-HTML + RegExp will tell you. There are a few fallbacks, most notably
<p style=">">would end up<p>">and a few other broken issues… I would recommend looking at Zend_Filter_StripTags as a more full proof tags/attributes filter in PHP