How to fix "Function eregi() is deprecated in PHP 5.3

Need some help with the script?

How to fix "Function eregi() is deprecated in PHP 5.3

Postby marcusmagalhaes » Mon Dec 28, 2009 3:04 pm

I used to use eregi for validating email address input that matches to the regular expression. (functions.inc.php)

if (!eregi('{(.*)}', $format)){


That would return true if given email address is matches to username@domain.ext pattern. Unfortunately, after upgrading PHP to the earlier version (5.3.0), it wont work properly. This is because eregi is one of several functions that are deprecated in the new version of PHP.

Solution:
Use preg_match with the ‘i’ modifier instead. i means that regular expression is case insensitive. So the code become like this:

Code: Select all
if (!preg_match('/{(.*)}/i', $format)){


cnr/show_news.php

Code: Select all
if (!$sort[0] or !eregi('(A|DE)SC', $sort[1])){
   $sort = array('date', 'DESC');
}

if (eregi('([0-9]{2}):([0-9]{2}):([0-9]{2})', $time)){
   $m_n = array('jan' => 1, 'fev' => 2, 'mar' => 3, 'abr' => 4, 'mai' => 5, 'jun' => 6, 'jul' => 7, 'ago' => 8, 'set' => 9, 'out' => 10, 'nov' => 11, 'dez' => 12);
    $time = explode(':', $time);
    $time = mktime($time[0], $time[1], $time[2], (eregi('[a-z]', $month) ? $m_n[$month] : $month), $day, $year);
}

if (eregi('[a-z]', $category)){
   $category = category_get_id($category);
}

if ($category and !eregi(',', $category)){
   $template = ((!eregi('(rss|print).php', $_SERVER['PHP_SELF']) and !$static and $cat_template[$category]) ? $cat_template[$category] : $template);
}


change to

Code: Select all
if (!$sort[0] or !preg_match('/(A|DE)SC/i', $sort[1])){
   $sort = array('date', 'DESC');
}
if (preg_match('/([0-9]{2}):([0-9]{2}):([0-9]{2})/i', $time)){
   $m_n = array('jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12);
    $time = explode(':', $time);
    $time = mktime($time[0], $time[1], $time[2], (eregi('[a-z]', $month) ? $m_n[$month] : $month), $day, $year);
}

if (preg_match('/[a-z]/i', $category)){
   $category = category_get_id($category);
}

if ($category and !preg_match('/,/i', $category)){
   $template = ((!preg_match('/(rss|print).php/i', $_SERVER['PHP_SELF']) and !$static and $cat_template[$category]) ? $cat_template[$category] : $template);
}



plugins.inc.php

Code: Select all
$result .= ($i ? '&' : '?').(!eregi('=', $array[1][$i]) ? $array[1][$i].'=$'.($i + 1) : $array[1][$i]);
   }


change to

Code: Select all
$result .= ($i ? '&' : '?').(!preg_match('/=/i', $array[1][$i]) ? $array[1][$i].'=$'.($i + 1) : $array[1][$i]);
   }


The list of functions that are deprecated in PHP 5.3.0:

* call_user_method() (use call_user_func() instead)
* call_user_method_array() (use call_user_func_array() instead)
* define_syslog_variables()
* dl()
* ereg() (use preg_match() instead)
* ereg_replace() (use preg_replace() instead)
* eregi() (use preg_match() with the ‘i’ modifier instead)
* eregi_replace() (use preg_replace() with the ‘i’ modifier instead)
* set_magic_quotes_runtime() and its alias, magic_quotes_runtime()
* session_register() (use the $_SESSION superglobal instead)
* session_unregister() (use the $_SESSION superglobal instead)
* session_is_registered() (use the $_SESSION superglobal instead)
* set_socket_blocking() (use stream_set_blocking() instead)
* split() (use preg_split() instead)
* spliti() (use preg_split() with the ‘i’ modifier instead)
* sql_regcase()
* mysql_db_query() (use mysql_select_db() and mysql_query() instead)
* mysql_escape_string() (use mysql_real_escape_string() instead)
* Passing locale category names as strings is now deprecated. Use the LC_* family of constants instead.
* The is_dst parameter to mktime(). Use the new timezone handling functions instead.
marcusmagalhaes
 
Posts: 163
Joined: Tue Apr 24, 2007 1:17 pm

Postby mark99 » Wed Dec 30, 2009 1:36 pm

Can you put that in a code tag so the text does not pickup smilies?
mark99
 
Posts: 123
Joined: Mon Feb 09, 2009 6:01 pm

Postby DarkSlim » Wed Jan 06, 2010 2:19 pm

So you have changed it all in your CNR installation and
it solved your problems with newer PHP versions?
It might be usefull for our own future CNR release :)
User avatar
DarkSlim
 
Posts: 296
Joined: Thu Aug 06, 2009 4:18 pm
Location: IL

Postby marcusmagalhaes » Fri Jan 08, 2010 11:52 am

I've change this and solved !!!!!! work's fine!!!
marcusmagalhaes
 
Posts: 163
Joined: Tue Apr 24, 2007 1:17 pm

Postby DarkSlim » Fri Jan 08, 2010 1:23 pm

Ok. awesome. thank you, I've added this to the Index :)
If anyone uses this too and can confirm it would be great too
User avatar
DarkSlim
 
Posts: 296
Joined: Thu Aug 06, 2009 4:18 pm
Location: IL

Postby Hawk » Sat Jan 09, 2010 1:03 pm

Thanks for the info, so far I haven't had any problems since I have php 5.2.11 on my hosting server, but it's good to have a solution if the problem shows up at some point.
User avatar
Hawk
 
Posts: 248
Joined: Tue Aug 29, 2006 9:00 pm

Postby svennis » Fri Mar 12, 2010 3:56 pm

I get this error:
Deprecated: Function eregi() is deprecated in /httpd.www/inc/functions.inc.php on line 731
I change eregi to preg_match and get this error:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /httpd.www/inc/functions.inc.php on line 731

am I missing something?

Code: Select all
function cache_remover($alone = ''){
   $fdir = opendir(rootpath.'/cache');
   while ($file = readdir($fdir)){
      if ($file != '.' and $file != '..' and $file != '.htaccess'){
         if ($alone){
            if (eregi($alone.'(.*).(short|full).', $file)){
               @unlink(rootpath.'/cache/'.$file);
            }

            if (!eregi('.(short|full).', $file)){
               @unlink(rootpath.'/cache/'.$file);
            }
         }

         if (!$alone){
            @unlink(rootpath.'/cache/'.$file);
         }
      }
   }

return true;
}


could you please modify this code to the right one?
tnx
svennis
 
Posts: 94
Joined: Mon Oct 09, 2006 2:54 pm

Postby svennis » Fri Mar 12, 2010 4:01 pm

I get same warning for syscon.mdu

Code: Select all
if (eregi('MSIE', $_SERVER['HTTP_USER_AGENT']) or eregi('Opera', $_SERVER['HTTP_USER_AGENT'])){


please help
svennis
 
Posts: 94
Joined: Mon Oct 09, 2006 2:54 pm

Postby Ma5ter » Wed Apr 21, 2010 6:52 am

svennis wrote:I get same warning for syscon.mdu

Code: Select all
if (eregi('MSIE', $_SERVER['HTTP_USER_AGENT']) or eregi('Opera', $_SERVER['HTTP_USER_AGENT'])){


please help




I had the same problem and made this, should work for you :)

Code: Select all
<?   
if (preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT']) or preg_match('/Opera/i', $_SERVER['HTTP_USER_AGENT'])){
?>







svennis wrote:I get this error:
Deprecated: Function eregi() is deprecated in /httpd.www/inc/functions.inc.php on line 731
I change eregi to preg_match and get this error:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /httpd.www/inc/functions.inc.php on line 731

am I missing something?

Code: Select all
function cache_remover($alone = ''){
   $fdir = opendir(rootpath.'/cache');
   while ($file = readdir($fdir)){
      if ($file != '.' and $file != '..' and $file != '.htaccess'){
         if ($alone){
            if (eregi($alone.'(.*).(short|full).', $file)){
               @unlink(rootpath.'/cache/'.$file);
            }

            if (!eregi('.(short|full).', $file)){
               @unlink(rootpath.'/cache/'.$file);
            }
         }

         if (!$alone){
            @unlink(rootpath.'/cache/'.$file);
         }
      }
   }

return true;
}


could you please modify this code to the right one?
tnx




Not tested, but worth trying this:

Code: Select all
function cache_remover($alone = ''){
   $fdir = opendir(rootpath.'/cache');
   while ($file = readdir($fdir)){
      if ($file != '.' and $file != '..' and $file != '.htaccess'){
         if ($alone){
            if (preg_match(/$alone.'(.*).(short|full)./i', $file)){
               @unlink(rootpath.'/cache/'.$file);
            }

            if (!preg_match('/.(short|full)./i', $file)){
               @unlink(rootpath.'/cache/'.$file);
            }
         }

         if (!$alone){
            @unlink(rootpath.'/cache/'.$file);
         }
      }
   }

return true;
}


Let me know if it works or not ;)
Ma5ter
 
Posts: 4
Joined: Wed Apr 21, 2010 6:49 am

Help Plzz!!

Postby ilyas_88 » Mon Apr 26, 2010 5:05 pm

Can you plz help me fix this error, I have the latest version of cutenews and my server is a PHP 5.3. I can not install the system :( getting this error:


Parse error: syntax error, unexpected T_NAMESPACE, expecting T_STRING or '(' in /customers/mydomen.net/mydomen.net/httpd.www/x/inc/functions.inc.php on line 863
test
ilyas_88
 
Posts: 32
Joined: Sun Jul 12, 2009 3:19 am
Location: norway

Re: Help Plzz!!

Postby marcusmagalhaes » Tue Apr 27, 2010 2:49 pm

try it...

////////////////////////////////////////////////////////
// Function: namespace
// Description: добавл?ет пор?дковый номер у "”–Ћу"

function url_namespace($str){
global $sql, $mod;

foreach ($sql->select(array('table' => 'news')) as $row){
if (@preg_match("/$str([0-9]+)?/i", $row['url'])){
$result[] = $row['id'];
}
}

$count = count($result);

if ($mod == 'addnews'){
$count++;
}

return totranslit($str.(($count and $count != 1) ? ' '.$count : ''));
}



ilyas_88 wrote:Can you plz help me fix this error, I have the latest version of cutenews and my server is a PHP 5.3. I can not install the system :( getting this error:


Parse error: syntax error, unexpected T_NAMESPACE, expecting T_STRING or '(' in /customers/mydomen.net/mydomen.net/httpd.www/x/inc/functions.inc.php on line 863
marcusmagalhaes
 
Posts: 163
Joined: Tue Apr 24, 2007 1:17 pm

Help Plzz!!

Postby ilyas_88 » Tue Apr 27, 2010 9:20 pm

it works!!!

thanks marcusmagalhaes, but when I open the homepage displays this error message: (i cant add news :( )

Deprecated: Function eregi() is deprecated in /customers/hawree.net/hawree.net/httpd.www/x/show_news.php on line 37

Deprecated: Function eregi() is deprecated in /customers/hawree.net/hawree.net/httpd.www/x/show_news.php on line 43



Can you PLZ help me with this error to :(
test
ilyas_88
 
Posts: 32
Joined: Sun Jul 12, 2009 3:19 am
Location: norway

Re: Help Plzz!!

Postby marcusmagalhaes » Wed Apr 28, 2010 2:09 am

look the first post.....

ilyas_88 wrote:it works!!!

thanks marcusmagalhaes, but when I open the homepage displays this error message: (i cant add news :( )

Deprecated: Function eregi() is deprecated in /customers/hawree.net/hawree.net/httpd.www/x/show_news.php on line 37

Deprecated: Function eregi() is deprecated in /customers/hawree.net/hawree.net/httpd.www/x/show_news.php on line 43



Can you PLZ help me with this error to :(
marcusmagalhaes
 
Posts: 163
Joined: Tue Apr 24, 2007 1:17 pm

Help Plzz!!

Postby ilyas_88 » Wed Apr 28, 2010 10:30 pm

I have done everything in the first post, but I cant add,edit news stell :(
test
ilyas_88
 
Posts: 32
Joined: Sun Jul 12, 2009 3:19 am
Location: norway

Re: Help Plzz!!

Postby marcusmagalhaes » Wed Apr 28, 2010 11:32 pm

// line 37 if (preg_match('/([0-9]{2}):([0-9]{2}):([0-9]{2})/i', $time)){
$m_n = array('jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12);
$time = explode(':', $time);
$time = mktime($time[0], $time[1], $time[2], (eregi('[a-z]', $month) ? $m_n[$month] : $month), $day, $year);
}

// line 43 if (preg_match('/[a-z]/i', $category)){
$category = category_get_id($category);
}


ilyas_88 wrote:I have done everything in the first post, but I cant add,edit news stell :(
marcusmagalhaes
 
Posts: 163
Joined: Tue Apr 24, 2007 1:17 pm

Next

Return to Help



Who is online

Users browsing this forum: No registered users and 4 guests

cron