Home  >  Article  >  Backend Development  >  How to delete span tag in php

How to delete span tag in php

青灯夜游
青灯夜游Original
2021-09-30 12:26:072691browse

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>";
?>

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)
  • 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>";
?>

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!

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