不赞成使用eregi()函数 [英] Function eregi() is deprecated

查看:509
本文介绍了不赞成使用eregi()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Function eregi() is deprecated. How can i replace eregi(). I try with preg_match but then stop working.

我们有此帮助吗?

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期望其正则表达式参数位于一对定界符之内.

preg_match expects its regex argument to be within a pair delimiters.

所以尝试:

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

这篇关于不赞成使用eregi()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆