警告:trim() 期望参数 1 是字符串,在 php 脚本中给出的数组 [英] Warning: trim() expects parameter 1 to be string, array given in php script

查看:44
本文介绍了警告:trim() 期望参数 1 是字符串,在 php 脚本中给出的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有php脚本,当我执行这段代码时,我收到警告

i have php script, when i executed this code, i got warning

警告:trim() 期望参数 1 是字符串,数组在 home/public_html 中给出

Warning: trim() expects parameter 1 to be string, array given in home/public_html

我为安全漏洞添加了 antixss 功能,如下面的代码.我该如何解决这个警告?

i've added antixss function for security vulnerability , like this code below. how do i resolve this warning?

<?php
$email_to = ""; 
$email_subject = ""; 
$success = ""; 

function antixss($value)
{
    $xss = htmlspecialchars(trim($value));
    return $xss;
}


if(!isset($_POST['First_Name']) ||
   !isset($_POST['Last_Name']) 
    {
    died('Sorry, there appears to be a problem.');      
}
$first_name =antixss($_POST['First_Name']); 
$last_name = antixss($_POST['Last_Name']);    

我该如何解决这个警告?谢谢

how do i resolve this warning? thanks

推荐答案

错误似乎是在您的 html 中,而不是在 php 中.

It appears the error is in your html and not in the php.

如果 $_POST['First_Name'] 是一个数组,而它不应该是一个数组,那么你的 html 可能看起来像:

If $_POST['First_Name'] is an array while it should not be, it is likely your html looks something like:

<input name="First_Name[]" ...>
                       ^^ here, remove this

这篇关于警告:trim() 期望参数 1 是字符串,在 php 脚本中给出的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆