Code for converting phphtml format to text format. There are many ways to convert html tags into plain text in php. for example, if php comes with the strip_tags function, it can directly convert html into plain text format, next, let me take a look at a variety of methods to convert html tags into plain text in php. for example, php comes with the strip_tags function, which can directly convert html to plain text format, next, let's take a look at various conversion codes.
Let's take a look at the strip_tags () function usage.
In the following example, all other tags are deleted:
The code is as follows: |
|
$ Input = "This example IsYanshare! "; Echo strip_tags ($ input ,""); ?>
Input result This example Is yanshare! |
The connection and connection content are filtered out. if you want to retain the content in A, refer to the following code:
Strip_tags has an optional parameter allowable_tags, which specifies the tag that can be skipped during this process. The following example uses strip_tags () to delete the HTML tag from the string:
The code is as follows: |
|
$ Input = "Email example@example.com "; Echo strip_tags ($ input ); ?> The following results are returned:
Email example@example.com |
A custom character set that converts html to a character set without html tags.
The code is as follows: |
|
Function html2text ($ str ){ $ Str = preg_replace ("/ |