JuicyJuice Posted January 28, 2010 Share Posted January 28, 2010 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: You did not supply a properly formatted value for email. But the thing is the e-mail is valid, anyone know of a solution? Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/ Share on other sites More sharing options...
JuicyJuice Posted January 28, 2010 Author Share Posted January 28, 2010 I typoed in the above post it's '/$this->ValidationExpression/' not /'$this->ValidationExpression/' still need a solution... Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1003291 Share on other sites More sharing options...
Alex Posted January 28, 2010 Share Posted January 28, 2010 Single quotes don't have variable interpolation. Try: if(!preg_match("/{$this->ValidationExpression}/", $this->Value)) { Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1003306 Share on other sites More sharing options...
Canguingo Posted May 22, 2011 Share Posted May 22, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1218799 Share on other sites More sharing options...
salathe Posted May 22, 2011 Share Posted May 22, 2011 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(). Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1218870 Share on other sites More sharing options...
Canguingo Posted May 23, 2011 Share Posted May 23, 2011 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? Thx in advance Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1219033 Share on other sites More sharing options...
salathe Posted May 23, 2011 Share Posted May 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1219040 Share on other sites More sharing options...
Canguingo Posted May 23, 2011 Share Posted May 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1219205 Share on other sites More sharing options...
Pikachu2000 Posted May 23, 2011 Share Posted May 23, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1219206 Share on other sites More sharing options...
Canguingo Posted May 23, 2011 Share Posted May 23, 2011 When posting code, enclose it within the forum's BBCode tags. sorry didn't know. Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1219211 Share on other sites More sharing options...
Canguingo Posted May 25, 2011 Share Posted May 25, 2011 Anybody a possible solution?? please... Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1219980 Share on other sites More sharing options...
salathe Posted May 25, 2011 Share Posted May 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1219990 Share on other sites More sharing options...
Canguingo Posted May 25, 2011 Share Posted May 25, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1220076 Share on other sites More sharing options...
Canguingo Posted May 25, 2011 Share Posted May 25, 2011 aaaah! got it!! hahaha it was the if (!preg_match($pattern, $mail_address)) { return true; } else { return false; } that ! was asking for the oposite right?? Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1220077 Share on other sites More sharing options...
salathe Posted May 25, 2011 Share Posted May 25, 2011 That's right. Quote Link to comment https://forums.phpfreaks.com/topic/190157-deprecated-function-eregi-is-deprecated/#findComment-1220110 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.