已弃用:C:\wamp\ 中的函数 eregi() 已弃用
请在使用 eregi() 函数验证电子邮件地址时出现此错误:
Deprecated: Function eregi() is deprecated in C:\wamp\www\ssiphone\classes\TraitementFormulaireContact.php on line 13
我的代码可能会出现问题:
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";
}
}
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";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
eregi
函数已被弃用,这意味着在 PHP 的未来版本中它将被删除。您可以用函数
preg_match
替换它,它的作用几乎相同。示例代码(未经测试):
/i 使其不区分大小写
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):
The /i makes it case insensitive
使用函数
preg_match()
你可以在这里找到 php 手册页: https://www.php.net/manual/en/function.preg-match.php
use the function
preg_match()
insteadyou can find the php manual page here: https://www.php.net/manual/en/function.preg-match.php
除了用
preg_*
替换ereg_*
之外,您还应该考虑内置的filter_var()
函数:您仍然会得到漏报(有很多您无法想象的有效电子邮件),但是它仍然比一个糟糕的正则表达式要好。
Aside from substituting
ereg_*
withpreg_*
, you should consider the builtinfilter_var()
function: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.