Author Topic: Deprecated: Function eregi() is deprecated  (Read 1525 times)

0 Members and 1 Guest are viewing this topic.

Offline JuicyJuiceTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Deprecated: Function eregi() is deprecated
« on: January 28, 2010, 03:20:57 PM »
Well hello everyone,

I've installed a fresh copy of Vanilla which is a lightweight forum.
But, I got a "Deprecated: Function eregi() is deprecated in C:\wamp\www\xfm\library\Framework\Framework.Class.Validator.php on line 93" when a user attempted to sign up.

So I went to find that function and found:

	
// Validate all defined variables
	
// Returns boolean value indicating un/successful validation
	
function 
Validate() {
	
	
// If a regexp was supplied, attempt to validate on it (empty strings allowed)
	
	
if(
$this->ValidationExpression != '' && $this->Value != '') {
	
	
	
if(!
eregi($this->ValidationExpression$this->Value)) {
	
	
	
	
$this->isValid 0;
	
	
	
	
$this->Context->WarningCollector->Add($this->ValidationExpressionErrorMessage);
	
	
	
}
	
	
}


So what I did was change it to:

	
// Validate all defined variables
	
// Returns boolean value indicating un/successful validation
	
function 
Validate() {
	
	
// If a regexp was supplied, attempt to validate on it (empty strings allowed)
	
	
if(
$this->ValidationExpression != '' && $this->Value != '') {
	
	
	
if(!
preg_match(/'$this->ValidationExpression/'$this->Value)) {
	
	
	
	
$this->isValid 0;
	
	
	
	
$this->Context->WarningCollector->Add($this->ValidationExpressionErrorMessage);
	
	
	
}
	
	
}


I no longer get the error but, now the board gives a:

Code: [Select]
You did not supply a properly formatted value for email.
But the thing is the e-mail is valid, anyone know of a solution?

Offline JuicyJuiceTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #1 on: January 28, 2010, 03:51:13 PM »
I typoed in the above post it's '/$this->ValidationExpression/' not /'$this->ValidationExpression/' still need a solution...

Offline Alex

  • Global Moderator
  • Addict
  • *
  • Posts: 2,487
  • Gender: Male
  • < 1 billion
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #2 on: January 28, 2010, 04:43:01 PM »
Single quotes don't have variable interpolation. Try:

if(!preg_match("/{$this->ValidationExpression}/"$this->Value)) {
« Last Edit: January 28, 2010, 04:45:50 PM by AlexWD »
:anim_rules: Read the rules, :rtfm: and don't forget to use [code] / [php] tags!


Offline Canguingo

  • Irregular
  • Posts: 7
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #3 on: May 22, 2011, 02:27:30 PM »
Hello,

I have the same problem, here is my code:

// DEFINE FUNCTIONS
function spamcheck($field)
{
    
//eregi() performs a case insensitive regular expression match
    
if (eregi("to:"$field) || eregi("cc:"$field) || eregi("bcc:"$field)) {
        return 
true;
    } else {
        return 
false;
    }
}
function 
check_email($mail_address)
{
    
$pattern "/^[\w-]+(\.[\w-]+)*@";
    
$pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i";
    if (!
preg_match($pattern$mail_address)) {
        return 
true;
    } else {
        return 
false;
    }
}

//END FUNCTIONS

Every time I run this code (contact form) I get the error "Deprecated: Function eregi() is deprecated ..."

However the email is sent.

Any solution?? Thanks in advance!
« Last Edit: May 23, 2011, 03:40:25 PM by Pikachu2000 »

Offline salathe

  • Lazy
  • Administrator
  • Addict
  • *
  • Posts: 1,540
  • Gender: Male
  • Temperament: Snuggly
    • View Profile
    • My Blog
Re: Deprecated: Function eregi() is deprecated
« Reply #4 on: May 22, 2011, 07:50:46 PM »
Any solution?? Thanks in advance!

The proper solution is to migrate your code to using one or more functions which are not considered deprecated. For regular expressions, that would be the PCRE functions (preg_match(), preg_replace(), etc.). An introduction to the differences between POSIX (ereg(), ereg_replace(), etc.) and PCRE functions can be found in the manual.

Many times, simple string functions can also be used. In your case, the eregi() function calls could be changed to use stripos().
« Last Edit: May 22, 2011, 07:51:18 PM by salathe »
PHP Documentation — Read it, or the badger will come for you.
http://php.net/manual/

Offline Canguingo

  • Irregular
  • Posts: 7
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #5 on: May 23, 2011, 08:04:31 AM »
Salathe,

thanks but if I use stripos() i get an error as if the email field was wrong or not filled in.

I've seen some answers that recomend to use preg_match() however when I use this one I ge : Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash 

Any other possible solutions?

thanks in advance

Offline salathe

  • Lazy
  • Administrator
  • Addict
  • *
  • Posts: 1,540
  • Gender: Male
  • Temperament: Snuggly
    • View Profile
    • My Blog
Re: Deprecated: Function eregi() is deprecated
« Reply #6 on: May 23, 2011, 08:36:26 AM »
Canguingo, please take the time to read the documentation (it takes a lot of effort to write it!) and understand how to use the functions that are suggested. It looks like you're just using them incorrectly. I gave you plenty of links through to the manual showing everything that you need to know.

stripos

Your code was:  if (eregi("to:", $field) || eregi("cc:", $field) || eregi("bcc:", $field)) {

Each of the eregi("...", $field) should become (stripos($field, "...") !== FALSE).  That will behave in the same way as your old code.

Another option is to use an equivalent PCRE regex:  if (preg_match('/to:|cc:|bcc:/', $field)) {

delimiters

As mentioned in the manual (I gave you this link earlier), PCRE patterns need delimiters whereas POSIX ones do not.  Your check_email() function already uses PCRE and has delimiters.
« Last Edit: May 23, 2011, 08:37:04 AM by salathe »
PHP Documentation — Read it, or the badger will come for you.
http://php.net/manual/

Offline Canguingo

  • Irregular
  • Posts: 7
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #7 on: May 23, 2011, 03:37:52 PM »
Thanx, I know you gave me that link already and I tryed to read it and understand it but for me is in chiness... I'm a bit new here. sorry about that.

I've try to use both examples you gave me. and with both i get the error that the email is invalid. See my code:

// DEFINE FUNCTIONS
function spamcheck($field)
{
    
//eregi() performs a case insensitive regular expression match. old comment..

    
if (preg_match("/to:|cc:|bcc:/"$field)) {
        return 
true;
    }
    else {
        return 
false;
    }
}
function 
check_email($mail_address)
{
    
$pattern "/^[\w-]+(\.[\w-]+)*@";
    
$pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i";
    if (!
preg_match($pattern$mail_address)) {
        return 
true;
    } else {
        return 
false;
    }
}


//END FUNCTIONS

if (isset($_REQUEST['send'])){
      if ((
$_REQUEST['naam']=="") OR ($_REQUEST['naam']=="")) {
                     echo 
"<p><b><br><FONT face=Verdana color=#ff7500 size=2>El campo 'nombre' es obligatorio.</FONT></b></b><p>";
      }
      elseif (isset(
$_REQUEST['email']))
        {
        
//check if the email address is invalid
        
$checkcode $_REQUEST['email'].$_REQUEST['bericht'].$_REQUEST['adres'].$_REQUEST['pcplaats'].$_REQUEST['bedrijf'].$_REQUEST['naam'];
        
$mailcheck spamcheck($checkcode);
        if (
$mailcheck==TRUE)
         {
         echo 
"Nice try.";
         
$klaar =1;
         }
        else { 
       
// check if address is an address 
         
$email $_REQUEST['email']; 
            if (
check_email($email)) {
               
//send email
               
$subject "Mensaje desde rcr66.com";
               
$message "De: ".$_REQUEST['naam']."( $email )";
               
               
$message .= "\n Calle: ".$_REQUEST['adres'];
               
$message .= "\n Ciudad: ".$_REQUEST['pcplaats'];
               
$message .= "\n Mensaje:";
               
$message .= $_REQUEST['bericht'];
               
mail("$emailto""$subject"$message"From: $email);
               echo 
"<p><br><b><FONT face=Verdana color=#ff7500 size=2>Gracias por tu mensaje, prometemos contestarte lo antes posible</FONT></b></br></p>";
               
$klaar =1;
            }
            else {
               echo 
"<p><b><br><font face=Verdana color=#ff7500 size=2>Fout email</font></br></b></p>";
            }
                           }
      }
}


Any idea where else do i need to change?
« Last Edit: May 23, 2011, 03:40:59 PM by Pikachu2000 »

Offline Pikachu2000

  • I hate everything.
  • Global Moderator
  • Freak!
  • *
  • Posts: 9,050
  • Gender: Male
  • Is it solipsistic in here, or is it just me?
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #8 on: May 23, 2011, 03:40:00 PM »
When posting code, enclose it within the forum's [code] . . . [/code] BBCode tags.
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf * || Linux Help --> linuxforum.com

Offline Canguingo

  • Irregular
  • Posts: 7
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #9 on: May 23, 2011, 03:44:58 PM »
Quote
When posting code, enclose it within the forum's  BBCode tags.

sorry didn't know.
« Last Edit: May 23, 2011, 03:45:43 PM by Canguingo »

Offline Canguingo

  • Irregular
  • Posts: 7
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #10 on: May 25, 2011, 08:30:00 AM »
Anybody a possible solution?? please...

Offline salathe

  • Lazy
  • Administrator
  • Addict
  • *
  • Posts: 1,540
  • Gender: Male
  • Temperament: Snuggly
    • View Profile
    • My Blog
Re: Deprecated: Function eregi() is deprecated
« Reply #11 on: May 25, 2011, 08:41:43 AM »
Your check_email() function returns TRUE if the email address does not match the regular expression and FALSE if the address does match the regular expression.  Your script looks to see if check_email() returned TRUE, and if it did then the email is sent via mail().

This logic seems backward to me: the email gets sent if the address does not look like an email address.
PHP Documentation — Read it, or the badger will come for you.
http://php.net/manual/

Offline Canguingo

  • Irregular
  • Posts: 7
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #12 on: May 25, 2011, 11:18:33 AM »
oh!  well that's probably what happens because everytime I write a correct email I get this error email from the last else in the code.

So what you say is that I should change something to make it the other way around. ... right? but what?

Offline Canguingo

  • Irregular
  • Posts: 7
    • View Profile
Re: Deprecated: Function eregi() is deprecated
« Reply #13 on: May 25, 2011, 11:21:32 AM »
aaaah! got it!! hahaha

it was the
Code: [Select]
if (!preg_match($pattern, $mail_address)) {        return true;    } else {        return false;    }

that ! was asking for the oposite right?? :)

Offline salathe

  • Lazy
  • Administrator
  • Addict
  • *
  • Posts: 1,540
  • Gender: Male
  • Temperament: Snuggly
    • View Profile
    • My Blog
Re: Deprecated: Function eregi() is deprecated
« Reply #14 on: May 25, 2011, 12:20:39 PM »
That's right.  :)
PHP Documentation — Read it, or the badger will come for you.
http://php.net/manual/