How to remove html tags in php

青灯夜游
Release: 2023-03-15 19:50:01
Original
4048 people have browsed it

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.

How to remove html tags in php

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)
Copy after login
ParametersDescription
stringRequired. 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(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = "Hello <b><i>world!</i></b>";
echo $str;
echo "<br>删除全部标签后: ".strip_tags($str);
echo "<br>保留b标签: ".strip_tags($str,"<b>");
?>
Copy after login

How to remove html tags in php

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!

Related labels:
php
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