I would like to delete all html tags (including their attributes such as class, src, id, etc.) on a string but I would like to retain <ul>,<li> and <br /> tags. How will I accomplish this?
Any suggestion would be greatly appreciated.
Thanks!
Use strip_tags() and pass in allowable tags. No need to re-invent the wheel. There are some security concerns with this method which might prevent you from using it. Please consider @Denis' answer if this is the case.
You can use a library such as html purifier:
Be wary of using strip_tags() with an argument:
strip_tags() to be less appropriate.