Home > Article > Backend Development > How to remove html tags in php
In php, you can use the strip_tags() function to remove html tags, the syntax is "strip_tags(string,allow)"; this function is used to strip HTM, PHP and other tags in the string, the parameter " allow" is used to specify the tags that need to be retained. If omitted, all tags will be deleted.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use strip_tags () function to remove html tags.
strip_tags() function strips HTML, XML and PHP tags from a string.
strip_tags() function accepts two parameters:
strip_tags(string,allow)
Parameters | Description |
---|---|
string | Required. Specifies the string to check. |
allow | Optional. Specifies allowed tags. These tags will not be deleted. |
If the "allow" parameter is omitted, all tags in the string will be deleted.
Example:
<?php header('content-type:text/html;charset=utf-8'); $str = "Hello <b><i>world!</i></b>"; echo $str; echo "<br>删除全部标签后: ".strip_tags($str); echo "<br>保留b标签: ".strip_tags($str,"<b>"); ?>
It can be seen that if the strip_tags() function omits the "allow" parameter, all tags will be deleted; if this parameter is set , you can retain specified tags, such as the tag in the above example, to achieve a bold effect.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove html tags in php. For more information, please follow other related articles on the PHP Chinese website!