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

What to do if thinkphp does not filter html tags

藏色散人
藏色散人 Original
2022-12-05 10:11:10 1987browse

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'];

The output content is as follows, the strip_tags() function does not play a role:

RWERWERWhgjghhfhgnbfghgh

RWERWERWhgjghhfhgnbfghgh

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:

RWERWERWhgjghhfhgnbfghgh

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!

Statement:
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