13
Jan
Learn how to use php strip_tags function
This strip_tags() is identical to htmlentities() function except strip_tags function strips HTML and PHP tags from a string.
Support – PHP 4, PHP 5
string strip_tags ( string $str [, string $allowable_tags ] )
This function tries to return a string with all NUL bytes, HTML and PHP tags stripped from a given str.
Parameters
str
The input string.
allowable_tags
You can use the optional second parameter to specify tags which should not be stripped.
- Note: HTML comments and PHP tags are also stripped. This is hardcoded and can not be changed with allowable_tags.
- Note: This parameter should not contain whitespace. strip_tags() sees a tag as a case-insensitive string between < and the first whitespace or >. It means that strip_tags(“<br>”, “<br/>”) returns an empty string.
<?php $text = ‘<p>Test String.</p>’; echo strip_tags($text); //Output: Test String ?>
<?php $text = ‘<p>Test String.</p>’; echo strip_tags($text,’<p>’); //Output: <p>Test String.</p> ?>