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

黄舟
Release: 2023-03-17 06:24:02
Original
1394 people have browsed it

Example

Strip the HTML tags in the string:

<?php
echo strip_tags("Hello <b>world!</b>");
?>
Copy after login

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)
Copy after login
ParametersDescription
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>");
?>
Copy after login

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);
?>
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template