Thinkphp automatically escapes the solution of reading errors caused by storing rich-text editor content _php tips

Source: Internet
Author: User

The convention.php in the thinkphp conf file has a configuration option

' Default_filter ' => ' htmlspecialchars ',//default parameter filtering method for I function ...
This method is turned on by default. In other words, the data we store in the database is htmlspecialchars by this function.

I used the kindeditor Rich Text editor in my project (maybe you're using Ueditor\ckeditor), edited the content of the article through a rich-text editor, and then stored it in the database and then read it from the database to the page.

In this process, I encountered a problem, when I was in the Insert method directly display I will be submitted to the database text data, the normal parsing into the HTML page, but when I read the HTML data from the database, the content of the article becomes an entire paragraph of HTML code. The dump outputs the contents of the array I read and can be clearly seen as being escaped.

1. What is stored in the database and an example of the content of the article read out:

<p>
 you know what?
</p>

2. Content effects parsed in HTML pages:

"<p>
 <span style=" White-space:pre "> </span> <span style= "White-space:pre"
> </span></p> "

It is obvious that the content that should have been HTML tags is now parsed into the contents of the text, with double quotes added to the outermost part of the text.

The normal display should be no double quotes. The database reads the data is the HTML page source code, then inserts the HTML page, the label is explained, the content inside the label displays the page.

Through the above analysis, can be determined, is thinkphp in the process of content storage automatically escape processing, resulting in the contents of the database into the escaped content, read out again when the HTML will automatically be the content of the original label to escape into the body text.

Therefore, decisively to the TP directory to find convention.php configuration file, the Default_filter function is disabled, later need to use the time to manually call it.

Test again, this time it solves the problem.

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.