0

For REGEX, I am wondering how I would clear all HTML tags entered except for the simple ones, such as <a>, <b>, <i>, <pre>. I know that I can use this regex to exclude all html charicters, but I am not sure how I would go about only removing some, and deleting the others while conserving the content inside. Thanks!

2
  • 2
    Have you considered using an HTML parser instead? Commented Feb 26, 2012 at 4:06
  • If regex is absolutely necessary, please state so. Otherwise, use a built in PHP function. Commented Feb 26, 2012 at 4:18

1 Answer 1

6

See the second parameter in :

http://php.net/strip_tags

Essentially, you can call this function and list the tags you don't' want to be stripped.

Sign up to request clarification or add additional context in comments.

1 Comment

It's not the requested regex, but regex is a but redundant for this. I agree that strip_tags should be used for this, and question should be revised to, "Is there a way to only allow certain HTML tags in PHP?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.