php String Filtering strip_tags of Function Usage Example Analysis

  • 2021-12-12 08:04:31
  • OfStack

This article illustrates the use of the php string filtering strip_tags () function. Share it for your reference, as follows:

strip_tags-Removes HTML and PHP tags from a string, very important function

(PHP 4, PHP 5, PHP 7)

string strip_tags ( string $str [, string $allowable_tags ] )

$str: Enter a string.
$allowable_tags: Optional, specifying a list of characters that are not removed.

What you do: Strip the HTML, XML, and PHP labels from the string.

Return value: Returns the stripped string.


<?php
$str = '<p><a href="jinsanguo.com" title=" Gold 3 Countries "><b><i> I'm from Kim 3 Countries </i></b></a></p>';
echo strip_tags($str); 
// When you right-click to view the source code, the output : I'm from Kim 3 Countries 
echo strip_tags($str,"<a>");
// When you right-click to view the source code, the output is: <a href="jinsanguo.com" title=" Gold 3 Countries "> I'm from Kim 3 Countries </a>
echo strip_tags($str,"<p> <b>");
// When you right-click to view the source code, the output is: <p><b> I'm from Kim 3 Countries </b></p>
echo strip_tags($str,"<p> <b> <a>");
// When you right-click to view the source code, the output is: <p><a href="jinsanguo.com" title=" Gold 3 Countries "><b> I'm from Kim 3 Countries </b></a></p>
?>

Run results:

I come from three countries of gold
< a href= "jinsanguo. com" title= "Gold 3" > I come from three countries of gold < /a >
< p > < b > I come from three countries of gold < /b > < /p >
< p > < a href= "jinsanguo. com" title= "Gold 3" > < b > I come from three countries of gold < /b > < /a > < /p >

For more readers interested in PHP related contents, please check the special topics of this site: "Summary of Common Functions and Skills of php", "Summary of Usage of php String (string)", "Encyclopedia of Operation Skills of PHP Array (Array)", "Introduction to Basic Grammar of PHP", "Introduction to Database Operation of php+mysql" and "Summary of Operation Skills of Common Database of php"

I hope this article is helpful to everyone's PHP programming.


Related articles: