【问题标题】:Fatal error: Uncaught ArgumentCountError: Too few arguments to function eregi(), 2 passed in致命错误:未捕获的 ArgumentCountError:函数 eregi() 的参数太少,传入 2
【发布时间】:2020-06-23 23:42:22
【问题描述】:

我将 PHP 版本从 PHP 5.3 升级到 PHP 7.4 并遇到错误。

if(!function_exists('ereg'))            { function ereg($pattern, $subject, &$matches) { return preg_match('/'.$pattern.'/', $subject, $matches); } }
if(!function_exists('eregi'))           { function eregi($pattern, $subject, &$matches) { return preg_match('/'.$pattern.'/i', $subject, $matches); } }
if(!function_exists('ereg_replace'))    { function ereg_replace($pattern, $replacement, $string) { return preg_replace('/'.$pattern.'/', $replacement, $string); } }
if(!function_exists('eregi_replace'))   { function eregi_replace($pattern, $replacement, $string) { return preg_replace('/'.$pattern.'/i', $replacement, $string); } }

此行出现错误:

if (eregi($urlregex, $URL)) { if($debug == "true") { logtofile("Debug :".$URL." is a valid URL."); } return $URL; }

错误是

致命错误:未捕获的 ArgumentCountError:参数太少 函数eregi(), 2 传入 C:\xampp\htdocs\bank\livechat\Code\library\jqSajax.class.php 上线 171 和 3 预计在 C:\xampp\htdocs\bank\livechat\Code\include\main_pre_body.php:5

我像这样把eregi()改成了preg_match()

if (preg_match($urlregex, $URL))
        {
            if($debug == "true")
            {
                logtofile("Debug :".$URL." is a valid URL.");
            }
            return $URL;
        }
        else
        {
            if($debug == "true")
            {
                logtofile("Error :".$URL." is not a valid URL.");
            }
            return "";
        }
    }

现在它显示了这个:

"警告: preg_match(): 未知修饰符'?'在 C:\xampp\htdocs\bank\livechat\Code\library\jqSajax.class.php171 行
"

谢谢

【问题讨论】:

  • 哪个正则表达式触发了这个错误?你可以试试var_dump($urlregex) 吗?
  • 如果 var_dump using (eregi($urlregex, $URL)) imgur.com/rRzFN0Q 会显示此错误
  • 和 C:\xampp\htdocs\bank\livechat\Code\include\main_pre_body.php 第 5 行是 imgur.com/dtSBpcO

标签: php wordpress


【解决方案1】:

你有:

if ( ! function_exists( 'eregi' ) ) {
    function eregi( $pattern, $subject, &$matches ) {
        return preg_match( '/' . $pattern . '/i', $subject, $matches );
    }
}

在你的第一个 sn-p 中,它用 3 个参数定义了函数,但是你有:

if ( eregi( $urlregex, $URL ) ) {
    if ( $debug == "true" ) {
        logtofile( "Debug :" . $URL . " is a valid URL." );
    }
    return $URL;
}

在您的第二个 sn-p 中,它仅使用 2 个参数调用该函数。

因此您需要提供所有 3 个参数,例如:

if ( eregi( $urlregex, $URL, &$matches ) ) {
    if ( $debug == "true" ) {
        logtofile( "Debug :" . $URL . " is a valid URL." );
    }
    return $URL;
}

【讨论】:

  • 但令人困惑的是 $matches 应该是什么?
  • 你的意思是变量包含什么?它是通过引用传递的,所以这取决于它来自代码中其他地方的位置......
  • 也许这会对你有所帮助 - $matches 包含结果,所以我不确定你在问什么...... php.net/manual/en/function.preg-match.php
猜你喜欢
  • 1970-01-01
  • 2018-04-16
  • 1970-01-01
  • 1970-01-01
  • 2019-06-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-11
  • 2018-06-26
相关资源
最近更新 更多