[ThinkPHP learning] ThinkPHP automatically escapes and stores Rich Text Editor content, leading to read errors,

Source: Internet
Author: User

[ThinkPHP learning] ThinkPHP automatically escapes and stores Rich Text Editor content, leading to read errors,

RT.

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:

& Lt; p & gt; do you know? & Lt;/p & gt;
2. Effect of the parsed content on the html page:

“        <p><span style="white-space:pre"></span><span style="white-space:pre"></span></p>”
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.





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.