PHP will be rich text editing content, remove style pictures, etc. only retain the TXT text content

Source: Internet
Author: User

1. Read the rich text content style from the database as follows:

<p style= "; text-indent:0;padding:0;line-height:26px" ><span style= "font-family: Microsoft ya black; Letter-spacing:0;font-size:14px ">    This is a small test! This is a small test! This is a small test! This is a small test! This is a small test! </span></p><p style= "; text-indent:0;padding:0;line-height:26px" >& Lt;span style= "font-family: Microsoft Jas Black; letter-spacing:0;font-size:14px" >    This is a small test! This is a small test! This is a small test! This is a small test! This is a small test! This is a small test! </span></p><p style= "text-indent:0px; padding:0px; line-height:26px; Text-align:center; " ><span style= "font-family: Microsoft Jas Black; letter-spacing:0;font-size:14px" ><

2. First, the pre-defined HTML entity "<" via PHP's htmlspecialchars_decode () function (less than) and ">" CONVERT (greater than) to a character, and then strip The HTML, XML, and PHP tags from the string with the Strip_tags () function to get the desired txt plain text content.

The implementation of the PHP core code is as follows:

$content _01 $data ["Content"]; // get Rich text content from a database $content _02 = Htmlspecialchars_decode ($content _01)// convert some pre-defined HTML entities to characters $ Contentsstrip_tags($content _02); // function Strips HTML, XML, and PHP tags from a string to get plain text content $con substr ($contents, 0,);//Returns the character of the first 300 string length in a string
Var_dump ($con);//Print output
Exit

PHP will be rich text editing content, remove style pictures, etc. only preserve txt text content

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.