弃用:函数eregi()在C:\wamp\中被弃用。

时间:2021-10-08 05:52:34

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

请在使用eregi()函数来验证邮件地址时,我得到了这个错误:

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

3 个解决方案

#1


3  

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

eregi函数被弃用,这意味着在将来的PHP版本中它将被删除。

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

可以用函数preg_match替换它,它几乎是一样的。

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

我使它不区分大小写。

#2


2  

use the function preg_match() instead

使用函数preg_match()代替。

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

您可以在这里找到php手册页:http://us3.php.net/manual/en/function.preg-match.php。

#3


1  

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

除了用preg_*替换ereg_*之外,您还应该考虑builtin filter_var()函数:

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.

你仍然会得到错误的否定(有很多你从未想过的有效电子邮件),但它仍然比一个糟糕的regexp要好。

#1


3  

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

eregi函数被弃用,这意味着在将来的PHP版本中它将被删除。

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

可以用函数preg_match替换它,它几乎是一样的。

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

我使它不区分大小写。

#2


2  

use the function preg_match() instead

使用函数preg_match()代替。

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

您可以在这里找到php手册页:http://us3.php.net/manual/en/function.preg-match.php。

#3


1  

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

除了用preg_*替换ereg_*之外,您还应该考虑builtin filter_var()函数:

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.

你仍然会得到错误的否定(有很多你从未想过的有效电子邮件),但它仍然比一个糟糕的regexp要好。