How to remove HTML tags from a string in PHP?

Last updated 5 years, 7 months ago | 1573 views 75     5

Tags:- PHP

PHP | strip_tags() function

strip_tags() function is use to remove HTML, XML, and PHP tags from string. The function provides you the ability to remove tags from strings. You can also ignore certain tags by using the second parameter.


string strip_tags ( string $str [, string $allowable_tags ] )

The function takes two parameters in which


Required. Specifies the string which is going to be check.


Optional. Specifies the tag which is allowed. These tags will not be removed.

echo strip_tags("Hello <b><i>world!</i></b>","<b>");

strip_tags function also remove HTML comments. The comments is always removed. This cannot be changed by using the allowable_tags parameter.