PHP Remove HTML tags from a String

PHP Remove HTML tags from a String :

PHP Remove HTML tags from a String

 The following code is used to remove the html tags from string.

<?php

$input=”Hi this is <b>TechniqZone</b>”;
$text = strip_tags($input, “”);
echo $text;
?>

Output is Hi this is TechniqZone.

The above code remove all html tags from string.

Here strip_tags() function is used to remove tags from string.

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


$allowable_tags – You can use the optional second parameter to specify tags which should not be stripped.

<?php

$input=”Hi this is lt;a href=’http://techniqzone.blogspot.in’><b>TechniqZone</b>lt;/a>”;
$text = strip_tags($input, “<b>”);
echo $text;
?>

Output is Hi this is TechniqZone. 

Here i allowed <b> tag from string.

Leave a Reply

Your email address will not be published. Required fields are marked *