There are many ways to convert HTML tags into plain text in PHP, like PHP comes with a function strip_tags it can convert HTML directly into plain text format, let me take a look at the various conversion code.
First look at the Strip_tags () function usage
The following example removes all tags except the tag:
| The code is as follows |
Copy Code |
|
$input = "This example
is yanshare! ";
Echo strip_tags ($input, "");
?>
Input results
This example
Is yanshare! |
Here the connection connection and the contents of the connection are filtered out, if we want to retain the content of a can refer to the following code
Strip_tags has an optional parameter allowable_tags specifies the tags that can be skipped during this procedure. The following example uses the Strip_tags () to delete the HTML tags in the string:
| The code is as follows |
Copy Code |
|
$input = "Email example@example.com";
echo Strip_tags ($input);
?>
This returns the following results:
Email example@example.com |
A custom character set that converts HTML to HTML-free tags, returns a converted string
| The code is as follows |
Copy Code |
|
function Html2text ($STR) {
$str = Preg_replace ("/ |