gpt4 book ai didi

php - trim() 期望参数 1 为字符串,数组中给出

转载 作者:行者123 更新时间:2023-12-02 17:39:05 25 4
gpt4 key购买 nike

我有这个 PHP 函数,用于将所有 html 特殊字符转换为 html 实体,UTF-8 兼容。

function safe($input) {

$text = trim($input); //<-- LINE 31

$text = preg_replace("/(\r\n|\n|\r)/", "\n", $text); // cross-platform newlines
$text = preg_replace("/\n\n\n\n+/", "\n", $text); // take care of duplicates

$text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
$text = stripslashes($text);

$text = str_replace ( "\n", " ", $text );
$text = str_replace ( "\t", " ", $text );

return $text;

}

现在,我使用 acunetix 网络漏洞扫描器检查我的脚本,我看到了这个错误:

This page contains an error/warning message that may disclose sensitive information.The message can also contain the location of the file that produced the unhandled exception.

This may be a false positive if the error message is found in documentation pages.
This vulnerability affects /cms/submit.php.
Discovered by: Scripting (Error_Message.script).
Attack details
URL encoded POST input access was set to 2
Error message found:

<b>Warning</b>: trim() expects parameter 1 to be string, array given in <b>C:\xampp\htdocs\cms\includes\safefunc.php</b> on line <b>31</b><br />

我该如何解决这个问题?

最佳答案

正如其他人所说,错误是不言自明的,并且此函数不是为处理数组而构建的。如果你需要处理数组那么像这样:

function safe($input) {
if(is_array($input)) {
return array_map('safe', $input);
}
// rest of code
}

关于php - trim() 期望参数 1 为字符串,数组中给出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22917107/

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