Home  >  Article  >  Backend Development  >  PHP strips the html, xml and php tags in the string function strip_tags()

PHP strips the html, xml and php tags in the string function strip_tags()

黄舟
黄舟Original
2017-11-04 09:55:261332browse

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

Since PHP 5.0 From now on, this function is binary safe.
Return value: Returns the stripped string
PHP Version: 4+
##Change Log: Since PHP 4.3, this function always strips HTML comments.
More examples

Example 1

Strip the HTML tags in the string, but allow the tag:

<?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 = &#39;<a href="/words?citype=0">新词库</a>&#39;;
echo $data;
echo "<br>";
echo strip_tags($data);
?>

Output|:

PHP strips the html, xml and php tags in the string function strip_tags()

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn