The eregi () function is deprecated

The eregi () function is deprecated. How can I replace eregi (). I try to use preg_match but then stop working.

i we 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';
        }
+5
source share
3 answers

preg_match expects its regex argument to be within the 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'; 
}     
+8
source

It seems you just forgot the separator

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

and

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

But in both cases, you should not use regular expressions, because they are much larger

$this->library_path[strlen($this->library_path) - 1] == '/'
substr($protocol, -3) == 'gd2'
+2
source

, strpos(). :

if(strpos('convert', $this->library_path) !== false) {
    // code here
}

: , END , Regex, substr():

if(substr($this->library_path, -7) == 'convert'  {
    //code here
}

7 - , strlen 0, . - , .

+1

All Articles