为什么我将此数组转换为字符串转换通知

时间:2010-10-10 19:08:40

标签: php

我正在使用电子贺卡程序here发送活动邀请并收到以下通知:

  

注意:数组转换为字符串   /nfs/c07/h01/mnt/108712/domains/christmasnativity.org/html/ecard/include/common.inc.php   在第32行

以下是第29至33行的代码:

/* Clean up request: Remove magic quotes, if the setting is enabled. */
if (get_magic_quotes_gpc()) {
  foreach($_REQUEST as $name => $value) 
    $_REQUEST[$name] = stripslashes($value);
}

可能导致此错误通知的任何线索?

感谢。

3 个答案:

答案 0 :(得分:4)

$_REQUEST中的一个值是数组。如果变量使用foo[]等名称,则会发生这种情况。

答案 1 :(得分:1)

您可以避免在像

这样的数组上运行stripslashes
if (get_magic_quotes_gpc()) {
  foreach($_REQUEST as $name => $value)
    if(!is_array($value)){
      $_REQUEST[$name] = stripslashes($value);
    }
}

但是数组$value内的值不会被剥离。

更完整的解决方案是这样的:

if (get_magic_quotes_gpc())
{
  strip_slashes_recursive($_REQUEST);
}

function strip_slashes_recursive(&$array)
{
  foreach ($array as $key => $value)
  {
    if (is_array ($value))
    {
      strip_slashes_recursive ($array[$key]);
    }
    else
    {
      $array[$key] = stripslashes($value);
    }
  }
}

答案 2 :(得分:0)

像Ignacio Vazquez-Abrams所说,其中一个$value是一个数组。您可以使用以下内容查看什么是数组(假设您可以/可以将结果输出到您可以看到的地方):

$_REQUEST[$name] = stripslashes($value);
var_dump($value);
相关问题