gpt4 book ai didi

PHP 添加 html 标签白名单以清理输入

转载 作者:行者123 更新时间:2023-11-30 22:33:41 25 4
gpt4 key购买 nike

我找到了 GUMP用于清理和验证数据输入的类,它的工作方式如下:

# Note that filters and validators are separate rule sets and method calls. There is a good reason for this.

require "gump.class.php";

$gump = new GUMP();

$_POST = $gump->sanitize($_POST); // You don't have to sanitize, but it's safest to do so.

$gump->validation_rules(array(
'title' => 'required',
'story' => 'required'

));

$gump->filter_rules(array(
'title' => 'trim|sanitize_string',
'story' => 'trim|sanitize_string',
));

$validated_data = $gump->run($_POST);

if($validated_data === false) {
echo $gump->get_readable_errors(true);
} else {
print_r($validated_data); // validation successful
}

在实际操作中,这很有效,并且可以清理所有输入数据。对于 story需要添加 html 标签的字段,如 <p><img><table>但是这个类 sanitizer 所有$_POST并删除所有 html 标签。

我找不到如何添加白名单 ( <p><img><table> ) 进行清理?!如何为 html 标签添加白名单?

最佳答案

A quick look at the class表明你不能那样做。

另一种解决方案是使用内置函数 strip_tags() .

关于PHP 添加 html 标签白名单以清理输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33156530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com