$text = '<div class="test"><p>Clean <a href="#">text</a><br><b>Bold</b> text</p></div>'; $cleanText = strip_tags($text, ['p','b','i','br']);
Removing all HTML tags from a string in PHP is a quite simple task using the built-in
strip_tags function. However, in some cases, you want to allow some elements. Fortunately, the strip_tags function allows this as well. As a second parameter, you can list the allowed tags as an array.
Note: This function should not be used to try to prevent XSS attacks. It does not modify any attributes on the tags that you allow.