当前位置: 首页 > 面试题库 >

不推荐使用函数eregi()

孟开宇
2023-03-14
问题内容

不推荐使用函数eregi()。我该如何替换eregi()。我尝试使用preg_match,但随后停止工作。

之前的代码:

if ( ! eregi("convert$", $this->library_path))
        {
            if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/";

            $this->library_path .= 'convert';
        }

if (eregi("gd2$", $protocol))
        {
            $protocol = 'image_process_gd';
        }

代码然后:

if ( ! preg_match("convert$/i", $this->library_path))
        {
            if ( ! preg_match("/$/i", $this->library_path)) $this->library_path .= "/";

            $this->library_path .= 'convert';
        }

if (preg_match("gd2$/i", $protocol))
        {
            $protocol = 'image_process_gd';
        }

问题答案:

preg_match 期望其正则表达式参数位于一对定界符内。

因此,请尝试:

if ( ! preg_match("#convert$#i", $this->library_path)) {
        if ( ! preg_match("#/$#i", $this->library_path)) 
                $this->library_path .= "/";

        $this->library_path .= 'convert';
}

if (preg_match("#gd2$#i", $protocol)) {                                         
        $protocol = 'image_process_gd'; 
}


 类似资料:
  • 问题内容: 我有以下使用函数在PHP 5.3之前运行良好的语句: 升级到PHP 5.3后,我收到了不赞成使用的警告: 不推荐使用:不推荐使用split()函数。 我正在尝试解析具有以下格式的字符串: 2010-08-10 23:07:58 成为其组成部分。 问题答案: 我认为您想要preg_split。

  • 问题内容: 我收到此警告,但是该程序仍然可以正常运行。 MySQL代码向我显示了一条PHP消息: 不推荐使用:mysql_connect():不推荐使用mysql扩展,以后将被删除:在第2行的C:\ xampp \ htdocs \ task \ media \ new \ connect.inc.php中使用mysqli或PDO代替 我的页面是 这是什么意思,我该如何消除该消息? 问题答案: 有

  • 问题内容: 我正在尝试使用和进行单元测试。 当我不包含注释时,测试将失败。但 不推荐使用MockitoJUnitRunner类型 我正在使用Mockito 2.6.9。我应该怎么做? 问题答案: 现在确实已弃用,应该改为使用。如您所见,仅软件包名称已更改,该类的简单名称仍为 。 摘录自javadoc : 移至,该课程将在Mockito 3中删除

  • 新的侦听器(又名OnCameraMoveListener())方法onCameraMove()没有CameraPosition CameraPosition输入变量,所以我很迷惑:有没有方法回收我的旧代码? 这里有一些参考资料。

  • 我收到这个警告,但程序仍然正常运行。 MySQL代码用PHP向我显示了一条消息: 不推荐使用:mysql_connect():不推荐使用mysql扩展,以后将删除该扩展:在C:\xampp\htdocs\task\media\new\connect.inc.php第2行使用mysqli或PDO 我的页是 这意味着什么,我如何消除消息?

  • 以及如何提供其值?