开发者

Deprecated: Function eregi() is deprecated in C:\wamp\

开发者 https://www.devze.com 2023-02-19 01:46 出处:网络
please when using the eregi() function to validate an email address i got this error: Deprecated: Function eregi() is deprecated in C开发者_开发技巧:\\wamp\\www\\ssiphone\\classes\\TraitementFormulai

please when using the eregi() function to validate an email address i got this error:

Deprecated: Function eregi() is deprecated in C开发者_开发技巧:\wamp\www\ssiphone\classes\TraitementFormulaireContact.php on line 13

my code which may make problem is :

 public function verifierMail($mail)
 {
    if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $mail)) {
      return "valid mail";
    }
    else {
      return "invalid mail";
    }
}


the eregi function is deprecated, which means that in future versions of PHP it will be removed.

You can replace it with the function preg_match which does pretty much the same thing.

Sample code (untested):

public function verifierMail($mail)
{
if(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $mail)) {
  return "valid mail";
}
else {
  echo "invalid mail";
}

The /i makes it case insensitive


use the function preg_match() instead

you can find the php manual page here: http://us3.php.net/manual/en/function.preg-match.php


Aside from substituting ereg_* with preg_*, you should consider the builtin filter_var() function:

filter_var($mail, FILTER_VALIDATE_EMAIL)

you'll still get false negatives (there are a lot of valid emails you'd never imagine), but it's still better than a poor regexp.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号