Home > Article > Backend Development > PHP strips the html, xml and php tags in the string function strip_tags()
Example
Strip the HTML tags in the string:
<?php echo strip_tags("Hello <b>world!</b>"); ?>
Definition and usage
strip_tags() function strips the HTML tags in the string HTML, XML and PHP tags.
Comments: This function always strips HTML comments. This cannot be changed via the allow parameter.
Note: This function is binary safe.
Syntax
strip_tags(string,allow)
Parameters | Description |
string | Required. Specifies the string to check. |
allow | Optional. Specifies allowed tags. These tags will not be deleted. |
Technical details
Return value: | Returns the stripped string |
PHP Version: | 4+ |
##Change Log: | Since PHP 5.0 From now on, this function is binary safe.Since PHP 4.3, this function always strips HTML comments. |
<?php echo strip_tags("Hello <b><i>world!</i></b>","<b>"); ?>The first parameter is required, that is, the source data of HTML and PHP tags must be removed. The second parameter is optional, indicating tags that do not need to be filtered. For example:
<?php $data = '<a href="/words?citype=0">新词库</a>'; echo $data; echo "<br>"; echo strip_tags($data); ?>Output|:
The above is the detailed content of PHP strips the html, xml and php tags in the string function strip_tags(). For more information, please follow other related articles on the PHP Chinese website!