Home > PHP Framework > ThinkPHP > What to do if thinkphp does not filter html tags

What to do if thinkphp does not filter html tags

藏色散人
Release: 2022-12-05 10:11:10
Original
2248 people have browsed it

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.

What to do if thinkphp does not filter html tags

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'];
Copy after login

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>
Copy after login

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[&#39;post&#39;][&#39;content&#39;] = strip_tags(htmlspecialchars_decode($data[&#39;post&#39;][&#39;post_content&#39;]));
 
echo  $data[&#39;post&#39;][&#39;post_content&#39;];
echo  $data[&#39;post&#39;][&#39;content&#39;];
Copy after login

The output is as follows, the conversion is successful:

<p>RWERWERWhgj<strong>ghhfhgn</strong>bfghgh</p>
RWERWERWhgjghhfhgnbfghgh
Copy after login

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!

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