Home >Backend Development >PHP Problem >How to delete span tag in php
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.
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='color:red;'>Hello</span> world!"; echo $str."<br>"; echo strip_tags($str)."<br>"; ?>
Output result:
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='color:red;'>Hello</span> <b>world!</b>"; echo $str."<br>"; echo strip_tags($str)."<br>"; echo strip_tags($str,"<b>")."<br>"; ?>
Output result:
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!