php – 函数eregi()已弃用

参见英文答案 > How can I convert ereg expressions to preg in PHP?                                    4个
函数eregi()已弃用.我怎样才能取代eregi().我尝试使用preg_match然后停止工作.

我们帮助他们:

http://takien.com/513/how-to-fix-function-eregi-is-deprecated-in-php-5-3-0.php

代码之前:

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'; 
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...