【问题标题】:strlen() expects parameter 1 to be string, array givenstrlen() 期望参数 1 是字符串,给定数组
【发布时间】:2013-06-01 15:23:50
【问题描述】:

我有一个使用 phorm 的旧网站。提交表单时出现此错误:

警告:strlen() 期望参数 1 为字符串,数组在 /home/user/public_html/form/phorm.php 的第 2015 行给出

我知道这是因为升级到 php 5.3,有没有一种简单的方法可以修复该行代码以使我的表单再次工作?

 if (strlen($PHORM_ALERTTO) && !strlen($PHORM_TO) && !$PHORM_INFONLY && !$ph_GotData) {
    $PHORM_TO = $PHORM_ALERTTO; //THIS IS LINE 2015





 Read the mail template file(s) and mail it (them) to the user */
  $ph_section = "user template";
  if (strlen($PHORM_ALERTTO) && !strlen($PHORM_TO) && !$PHORM_INFONLY && !$ph_GotData) {
    $PHORM_TO = $PHORM_ALERTTO; //THIS IS LINE 2015
    settype($PHORM_TO, "array");
  }
  if (isset($PHORM_TMPL) && isset($PHORM_TO) && !$ph_Abort) {
    if ($ph_debug2) echo "<B>JS:</B> Mail Template(s)<BR>";

    if (count($PHORM_TMPL) > $ph_MaxTMPL) $ph_Alerts['120'] = ph_Message("A120");

    list(,$fPHORM_TO)      = each($PHORM_TO);
    list(,$fPHORM_SUBJECT) = each($PHORM_SUBJECT);

    while ($ph_MaxTMPL-- && list($ph_key, $lPHORM_TMPL) = each($PHORM_TMPL)) {
      if ($lPHORM_TMPL == ph_GENERIC) $lPHORM_TMPL = "$ph_root/files/generic.txt";
      else                            $lPHORM_TMPL = "$ph_tpd/$lPHORM_TMPL";

      $ph_Message   = "";
      $ph_Headers   = "";
      $ph_NonHeader = "";

      $lPHORM_TO      = "";
      $lPHORM_FROM    = "";
      $lPHORM_SUBJECT = "";
      $lPHORM_HEADERS = "";

      $ph_TemplateHeaders = false;
      if (ereg("(.+) +\+h$", $lPHORM_TMPL, $ph_regs)) {
        $lPHORM_TMPL = trim($ph_regs[1]);
        $ph_TemplateHeaders = true;
      }

      if ($ph_debug8) echo "Mail Template <B>$lPHORM_TMPL</B><BR>";

      if (!$ph_Template = @implode("", file($lPHORM_TMPL))) {
        $ph_Alerts['005'] = ph_Message("A005");
        if ($php_errormsg) $ph_Alerts['005P'] = "%%%: $php_errormsg";
        continue;
      }

【问题讨论】:

  • 那是因为,你只能用它来统计字符串,如果你想统计一个数组使用count()
  • 警告中都说了...
  • 有什么建议我需要在该行代码中进行更改吗?
  • if (strlen($PHORM_ALERTTO) && !strlen($PHORM_TO) && !$PHORM_INFONLY && !$ph_GotData) { $PHORM_TO = $PHORM_ALERTTO; //这是 2015 年的 LINE

标签: php arrays strlen


【解决方案1】:

这是因为您使用strlen() 来计算数组,而当您需要计算字符串时应该使用它。你的错误很明显。

如果您需要计算一个或多个数组,只需使用countsizeof 函数。

【讨论】:

  • @PeterEastwood 错误意味着您将函数 strlen 用于数组,因此 $PHORM_ALERTTO 和/或 $PHORM_TO 都是数组,请尝试更改为 if (count($PHORM_ALERTTO) &amp;&amp; !count($PHORM_TO) &amp;&amp; !$PHORM_INFONLY &amp;&amp; !$ph_GotData) { $PHORM_TO = $PHORM_ALERTTO;
猜你喜欢
  • 2020-01-27
  • 1970-01-01
  • 1970-01-01
  • 2016-10-10
  • 2021-01-13
  • 2015-07-12
  • 2016-04-30
  • 2014-12-09
相关资源
最近更新 更多