PHP HTML format to Text Format Code _php tutorial

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

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.