Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function eregi() is deprecated [duplicate]

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

i us ethis help:

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

CODE BEFORE:

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

CODE THEN:

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';
        }
like image 308
senzacionale Avatar asked Apr 18 '11 09:04

senzacionale


2 Answers

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

So try:

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'; 
}     
like image 106
codaddict Avatar answered Sep 16 '22 13:09

codaddict


It seems you just forgot the Delimiter

preg_match("~/$~", $this->library_path)

and

preg_match("~gd2$~i", $protocol)

But in both cases you should consider not using regular expressions, because they are oversized here

$this->library_path[strlen($this->library_path) - 1] == '/'
substr($protocol, -3) == 'gd2'
like image 37
KingCrunch Avatar answered Sep 19 '22 13:09

KingCrunch