PHP can delete HTMl tags in three ways. Method 1: directly retrieve the tag you want to retrieve and copy the code as follows :? Php retrieves the br tag functionstrip ($ str) {$ strstr_replace (br, $ str); $ strhtmlspecialchars ($ str );
Method 1:
Directly retrieve the tag
The code is as follows:
// Retrieve the br Mark
Function strip ($ str)
{
$ Str = str_replace ("
"," ", $ Str );
// $ Str = htmlspecialchars ($ str );
Return strip_tags ($ str );
}
?>
Method 2.
PHP has a strip_tags function to easily remove HTML tags.
Echo strip_tags ("Hello
World"); // Remove HTML, XML, and PHP labels.
Non-standard HTML code can also be correctly removed:
Echo strip_tags ("\"> cftea "); // output cftea
In PHP, you can use the strip_tags function to remove HTML tags. See the following example:
The code is as follows:
$ Str = 'www
Dreamdu
. Com ';
Echo (htmlspecialchars ($ str )."
");
Echo (strip_tags ($ str ));
?>
Method 3.
The strtr () function converts special characters in a string.
Syntax
Strtr (string, from,)
Or
Strtr (string, array)
Parameters |
Description |
String1 |
Required. Specifies the string to be converted. |
From |
Required (unless an array is used ). Specifies the character to be changed. |
To |
Required (unless an array is used ). Specifies the character to be changed. |
Array |
Required (unless you useFromAndTo). An array where the key is the original character and the value is the target character. |
Example 1:
The code is as follows:
Echo strtr ("Hilla Warld", "ia", "eo ");
?>
Example 2:
The code is as follows:
$ Arr = array ("Hello" => "Hi", "world" => "earth ");
Echo strtr ("Hello world", $ arr );
?>
The token directly retrieves the tag code you want to retrieve :? Php // remove the br flag function strip ($ str) {$ str = str_replace ("br", "", $ str ); // $ str = htmlspecialchars ($ str );...