Search code examples
phpdeprecatedposix-ere

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


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";
    }
}

Solution

  • 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