How to remove HTML tags form a string in PHP?

374 Views

How to remove HTML tags form a string in PHP?

strip_tags() function

strip tags is an inbuilt function in PHP.

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

Syntax

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

The function takes two parameter in which

$str

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

$allowable_tags

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

 <?php
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 allowable_tags parameter.

Tags:-
PHP

Today spacial posts