Phphtml format to text format code _ PHP Tutorial

Source: Internet
Author: User
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 ("/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.