Three solutions for php to delete html tags: phphtml labels
This article describes three methods for deleting HTMl tags in PHP.
Method 1:
Directly retrieve the tag
<? Php // remove the br Flag function strip ($ str) {$ str = str_replace ("<br>", "", $ str ); // $ str = htmlspecialchars ($ str); return strip_tags ($ str);} // edit by www.jbxue.com?>
Method 2.
PHP has a strip_tags function to easily remove HTML tags.
Echo strip_tags ("Hello <B> World </B>"); // remove HTML, XML, and PHP labels.
Non-standard HTML code can also be correctly removed:
Echo strip_tags ("<a href = \"> cftea </a> "); // output cftea
In PHP, you can use the strip_tags function to remove HTML tags. See the following example:
<?php$str = ‘www.<p>jbxue</p>.com';echo(htmlspecialchars($str).”<br>”);echo(strip_tags($str));?>
Method 3.
The strtr () function converts special characters in a string.
Syntax
Strtr (string, from,)
Or
Strtr (string, array)
Parameter description
String1 is required. Specifies the string to be converted.
From is required (unless an array is used ). Specifies the character to be changed.
To is required (unless an array is used ). Specifies the character to be changed.
Array is required (unless from and to are used ). An array where the key is the original character and the value is the target character.
Example 1:
<?phpecho strtr("Hilla Warld","ia","eo");?>
Example 2:
<?php$arr = array("Hello" => "Hi", "world" => "earth");echo strtr("Hello world",$arr);?>