Help converting PHP eregi to preg_match

I am wondering if anyone can help me convert a piece of PHP code that is now deprecated.

Here is one line I'm trying to convert:

if(eregi(trim ($request_url_handler[$x]),$this->sys_request_url) && $this->id_found == 0){

This is part of a function that returns configuration settings for a website. Below is the whole function.

// GET CORRECT CONFIG FROM DATABASE
function get_config($db)
{
    global $tbl_prefix;
    $db->query("SELECT cid,urls FROM ".$tbl_prefix."sys_config ORDER BY cid");

    while($db->next_record()){
        $request_url_handler = explode("\n",$db->f("urls"));
        if(empty($request_url_handler[0])) {
            $request_url_handler[0] = "@";
            $this->id_found = 2;
        }

        for($x=0; $x<count($request_url_handler); $x++) {
            if(empty($request_url_handler[$x])) {
                $request_url_handler[$x] = "@";
            }
            if(eregi(trim($request_url_handler[$x]),$this->sys_request_url) && $this->id_found == 0) {
                $this->set_config($db,$db->f("cid"));
                $this->id_found = 1;
            }
        }

        if($this->id_found == 1) {
            return($this->sys_config_vars);
        }
    }

    $this->set_config($db,"");
    return($this->sys_config_vars);
}

Any help would be greatly appreciated. I only found that the eregi function is deprecated as I upgraded XAMPP to 1.7.3.

+3
source share
1 answer

Try replacing:

if(eregi(trim($request_url_handler[$x]),$this->sys_request_url) && $this->id_found == 0) {

with:

$request_url_handler[$x] = trim($request_url_handler[$x]);
if( preg_match("/$request_url_handler[$x]/i",$this->sys_request_url) && $this->id_found == 0) {

eregideprecated and we need to use preg_matchwith the option ias a replacement.

Usually

eregi($regex,$input)

can be replaced by:

preg_match("/$regex/i",$input)

EDIT:

, $regex /, . , : @ # |, $regex

preg_match("#$regex#i",$input)

$regex.

+3

Source: https://habr.com/ru/post/1741717/


All Articles