ThinkPHP automatically escapes and stores rich text editor content, causing reading errors, _PHP tutorial

WBOY
Release: 2016-07-13 10:21:04
Original
1119 people have browsed it

Solution to the problem of reading errors caused by ThinkPHP automatically escaping and storing rich text editor content,

Convention.php in ThinkPHP’s conf file has a configuration option

'DEFAULT_FILTER' => 'htmlspecialchars', // Default parameter filtering method for I function...
This method is enabled by default. In other words, the data we store in the database will be escaped by the htmlspecialchars function.

I use the Kindeditor rich text editor in my project (maybe you are using Ueditorckeditor). I edit the content of the article through the rich text editor and store it in the database, and then read it from the database and display it on the web page. .

During this process, I encountered a problem. When I directly display the text data I will submit to the database in the insert method, it can be parsed into an HTML page normally, but when I read the HTML data from the database , the article content becomes a whole piece of HTML code. The dump outputs the contents of the array I read, and I can clearly see that the contents have been escaped.

1. Examples of content stored in the database and read article content:

<p>
 你们知道吗?
</p>
Copy after login

2. The content effect parsed in the html page:

“<p>
 <span style="white-space:pre"> </span><img src="/17joys/Public/kindeditor/attached/image/20140807/20140807110915_31727.jpg" alt="" width="800" height="600">
<span style="white-space:pre"> </span></p>”

Copy after login

It is obvious that the content that should be turned into HTML tags is now parsed into the content in the text, and double quotes are added to the outermost part of the text content.

Normal display should be without double quotes. The data read from the database is the source code of the HTML page. After inserting into the HTML page, the tags are interpreted and the content in the tags is displayed as a page.

Through the above analysis, it can be determined that ThinkPHP automatically escapes the content during the content storage process, causing the content stored in the database to become escaped content. When it is read out again, it is HTML Content that originally belongs to the tag will be automatically escaped into body text.

So, decisively go to the conf directory of TP to find the convention.php configuration file, disable the DEFAULT_FILTER function, and call it manually when you need to use it in the future.

Test again, this time the problem is solved.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/861795.htmlTechArticleThinkPHP automatically escapes the solution to store rich text editor content, causing reading errors, in ThinkPHP's conf file Convention.php has a configuration option 'DEFAULT_FILTER' = 'htmlspecia...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template