Reputation: 165
I use htmlspecialchars function in my string. But, I don't want to clean them;
<b>, <br>, <p> <ul>,<li> bla bla...
Example: Mystring = "<script>.....</script><br><b>test</b><p>aaaa</p>";
I want to; =
<script>.....</script>
Upvotes: 4
Views: 2409
Reputation:
You can use built in PHP function: strip_tags($text, '<p><a><li><b>');
You don't need to use any class or external library, to remove HTML tags from user input.
In the above example I am cleaning the $text from all tags except <p><a><li><b>
;
This PHP function will clean user input making sure are not submitting <script>
or </div>
to break your page.
Upvotes: 1
Reputation: 1040
You can use HTML Sanitizer Class - http://www.phpclasses.org/browse/package/3746.html
Upvotes: 2
Reputation: 8011
Have a look at HTML Purifier, and especially the whitelist feature.
This is probably the safest approach if you allow HTML tags. You can view the comparison here.
Upvotes: 7