How to delete span tag in php

青灯夜游
Release: 2023-03-13 07:32:01
Original
2555 people have browsed it

In PHP, you can use the strip_tags() function to delete span tags. This function can strip HTML, XML and PHP tags in a string. The syntax is "strip_tags(string,allow)"; allow is An optional parameter that specifies the tags that can be retained.

How to delete span tag in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php delete span tag

In PHP, you can use the strip_tags() function to delete span tags.

<?php
header("Content-type:text/html;charset=utf-8");
$str = "<span style=&#39;color:red;&#39;>Hello</span> world!";
echo $str."<br>";
echo strip_tags($str)."<br>";
?>
Copy after login

Output result:

How to delete span tag in php

The strip_tags() function strips HTML, XML and PHP tags from the string. Syntax format:

strip_tags(string,allow)
Copy after login
  • string Required. Specifies the string to check.

  • #allow Optional. Specifies allowed tags. These tags will not be deleted.

<?php
header("Content-type:text/html;charset=utf-8");
$str = "<span style=&#39;color:red;&#39;>Hello</span> <b>world!</b>";
echo $str."<br>";
echo strip_tags($str)."<br>";
echo strip_tags($str,"<b>")."<br>";
?>
Copy after login

Output result:

How to delete span tag in php

Comments: This function always strips HTML comments. This cannot be changed via the allow parameter.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to delete span tag 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!