Home >PHP Framework >ThinkPHP >What to do if thinkphp does not filter html tags
The solution to thinkphp not filtering html tags: 1. Open the corresponding tp file; 2. Use the "strip_tags(htmlspecialchars_decode($data['post']['post_content'])); method to The converted entity can be reversed.
The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.
What should I do if thinkphp does not filter html tags?
TP5 The solution to using strip_tags to filter html tags does not work
The solution to using strip_tags to filter html tags in ThinkPHP5 does not work
During the article saving process, you need to obtain the text in the html content edited by the Uediter editor on the front end. The basic idea is to use PHP's own function strip_tags() to directly filter
So edit it directly as follows:
$data = $this->request->param(); $data['post']['content'] = strip_tags($data['post']['post_content']); echo $data['post']['post_content']; echo $data['post']['content'];
The output content is as follows, the strip_tags() function does not play a role:
<p>RWERWERWhgj<strong>ghhfhgn</strong>bfghgh</p> <p>RWERWERWhgj<strong>ghhfhgn</strong>bfghgh</p>
Looking at the TP5 manual-input variable chapter-variable filtering we can find out By default, TP5 uses htmlspecialchars to convert the string passed from the front end into HTML entities. Therefore, my solution is to reverse the converted entities. This can be achieved by using the htmlspecialchars_decode() function:
$data = $this->request->param(); $data['post']['content'] = strip_tags(htmlspecialchars_decode($data['post']['post_content'])); echo $data['post']['post_content']; echo $data['post']['content'];
The output is as follows, the conversion is successful:
<p>RWERWERWhgj<strong>ghhfhgn</strong>bfghgh</p> RWERWERWhgjghhfhgnbfghgh
Recommended learning: "thinkPHP Video Tutorial"
The above is the detailed content of What to do if thinkphp does not filter html tags. For more information, please follow other related articles on the PHP Chinese website!