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>
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>”
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.