gpt4 book ai didi

php - FILTER_SANITIZE_FULL_SPECIAL_CHARS 和 htmlspecialchars 有什么区别?

转载 作者:行者123 更新时间:2023-12-05 06:42:56 24 4
gpt4 key购买 nike

我有一个文本区域,用户可以将其作为评论框使用,因此可以接受任何类型的输入,但只能将其作为文本而不是代码接受。基本上我想保护我的数据库。我不想剥离标签或类似的东西,我只是希望如果任何用户甚至输入应该作为文本存储在数据库中并且不应该对数据库造成任何损害的代码。所以现在遇到了这两个 php 函数,我不确定应该使用哪一个,因为我无法理解它们之间的区别。

最佳答案

根据官方 PHP 文档,htmlspecialchars()FILTER_SANITIZE_FULL_SPECIAL_CHARS 应该 是等价的:

Equivalent to calling htmlspecialchars() with ENT_QUOTES set. Encoding quotes can be disabled by setting FILTER_FLAG_NO_ENCODE_QUOTES. Like htmlspecialchars(), this filter is aware of the default_charset and if a sequence of bytes is detected that makes up an invalid character in the current character set then the entire string is rejected resulting in a 0-length string. When using this filter as a default filter, see the warning below about setting the default flags to 0.

取自此处 - https://www.php.net/manual/en/filter.filters.sanitize.php

从这里开始,我认为您更喜欢哪个功能将是个人喜好问题。

关于php - FILTER_SANITIZE_FULL_SPECIAL_CHARS 和 htmlspecialchars 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35429499/

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