ThinkPHP automatic escape storage rich text editor content causes read error solution, _ PHP Tutorial

Source: Internet
Author: User
ThinkPHP automatically escapes the solution for reading errors caused by storing rich text editor content ,. ThinkPHP automatically escapes the solution to read errors caused by storing rich text editor content, Convention in the conf file of ThinkPHP. php has a configuration option DEFAULT_FILTERhtmlspecia ThinkPHP to automatically escape the solution that stores rich text editor content and causes read errors,

Convention. php in the conf file of ThinkPHP has a configuration option.

'Default _ filter' => 'htmlspecialchars', // The DEFAULT parameter filtering method is used for the I function...
This method is enabled by default. That is to say, all the data we store in the database will be escaped by the htmlspecialchars function.

In my project, I used the Kindeditor rich text editor (maybe you are using Ueditor \ ckeditor), edited the content of the article through the rich text editor, and stored it in the database, then, read and display the data from the database to the webpage.

In this process, I encountered a problem. when the insert method directly shows the text data that I will submit to the database, it can be parsed into an HTML page, however, when I read HTML data from the database, the content of the article becomes a whole HTML code. Dump outputs the array content that I read. it is clear that the content has been escaped.

1. examples of the content stored in the database and the content of the read articles:

Do you know?

2. Effect of the parsed content on the html page:

Obviously, the content that should have been converted into HTML tags is now parsed into the content in the text, and double quotation marks are added to the outermost side of the text content.

The normal display should be without double quotation marks. The data read by the database is the source code of the HTML page. after the HTML page is inserted, the tag is interpreted and the content in the tag is displayed as a page.

Through the above analysis, we can determine that ThinkPHP automatically escaped the content during the content storage process, resulting in the content stored in the database being converted into the escaped content, when the tag is read again, HTML automatically escapes the content of the tag to the body text.

Therefore, find the convention. php configuration file in the conf directory of TP, disable the DEFAULT_FILTER function, and manually call it later.

Test again and solve the problem this time.




Convention. php in the conf file of ThinkPHP has a configuration option 'default _ filter' = 'htmlspecia...

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.