Function eregi() is deprecated, any replacement?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

alexan
New php-forum User
New php-forum User
Posts: 3
Joined: Sat Mar 12, 2011 12:09 am

Function eregi() is deprecated, any replacement?

Postby alexan » Sun Mar 13, 2011 8:10 am

Hi

I'm using CcMail newsletter in my website and the logs of apache are full of
PHP Deprecated: Function eregi() is deprecated


I did a search in the code and i have found the function in a couple of places.
The first one is like below to check if the three variables are numeric with values 0-9,
Any suggestion of how can i replace this?

Code: Select all

eregi("^[0-9]+$", $applied_settings['max_displayed_recipients'])


Also in another file it checks if the email address is valid,
any suggestion on that?

Code: Select all

function validate_email($email)
{
   $regexp = "^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$";
   if (eregi($regexp, $email)) return true;
   else return false;
}


and the third place i have found the code is

Code: Select all

eregi("\.ccmail$", $file)


and i don't understand what it does, does it have to do with the extension of the file?

Thank you for your time
Alex

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Function eregi() is deprecated, any replacement?

Postby egami » Mon Mar 14, 2011 6:25 am

preg_match() will probably be your best bet.

alexan
New php-forum User
New php-forum User
Posts: 3
Joined: Sat Mar 12, 2011 12:09 am

Re: Function eregi() is deprecated, any replacement?

Postby alexan » Mon Mar 14, 2011 7:54 am

Thank you for your reply,

so there is no regular expression function in php any more,
how can anybody replaced with it with a substring search function?

I have also searched for a email validation code in php,
every single piece of code i found was using eregi().

I see a lot of websites having problems when eregi() is removed.

Alex

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Function eregi() is deprecated, any replacement?

Postby Nullsig » Mon Mar 14, 2011 10:39 am

so there is no regular expression function in php any more,


As egami stated "preg_match() will probably be your best bet."

eregi uses POSIX for its regular expressions, preg uses PERL. You will need to rewrite your expressions to fit the PERL syntax but it is faster than eregi which is why ereg has been deprecated.

alexan
New php-forum User
New php-forum User
Posts: 3
Joined: Sat Mar 12, 2011 12:09 am

Re: Function eregi() is deprecated, any replacement?

Postby alexan » Mon Mar 14, 2011 11:38 am

Thank you for your reply

It was my mistake actually , i thought that the preg_match was a substring search function but it is actually a similar regular expression function.

Alex

ffnick
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Feb 21, 2013 2:42 am

Re: Function eregi() is deprecated, any replacement?

Postby ffnick » Thu Feb 21, 2013 3:33 am

eregi functionality have been replaced with preg_match.
Hopefully my hack of ccmail scripts will help ccmail users to get ccmail working enough to export their mailing list. I am not a fluent PHP nor Perl coder. Please do not ask me to help.
I am using ccmail version 1.02 so files may be different.

eregi appears in two files
admin.php and functions/shared.php

First of all overwrite eregi with preg_match in both files.
Then wrap the strings in / and /i

In admin.php on line 585 replace

Code: Select all

if (eregi("^[0-9]+$", $applied_settings['max_displayed_recipients']) && eregi("^[0-9]+$", $applied_settings['pause_for']) && eregi("^[0-9]+$", $applied_settings['pause_every']))


with

Code: Select all

if (preg_match("/^[0-9]+$/i", $applied_settings['max_displayed_recipients']) && preg_match("/^[0-9]+$/i", $applied_settings['pause_for']) && preg_match("/^[0-9]+$/i", $applied_settings['pause_every']))


In functions/shared.php on line 45 replace

Code: Select all

 if (eregi('$regexp', '$email')) return true;


with

Code: Select all

if (preg_match('/$regexp/i', '$email')) return true;


Hope that helps.
Then export your collected email addresses and use another free mailing list.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests

cron