替代php中的eregi()
作者:互联网
参见英文答案 > How can I convert ereg expressions to preg in PHP? 4个
> Alternative Function for EREGI in PHP 1个
所以,我在我的邮件脚本中使用了eregi,但是最近,我得到了该函数被弃用的错误.
那么,替换以下代码的最简单方法是什么:
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email'])))?
任何帮助表示赞赏:)
解决方法:
if (!preg_match("/^[A-Z0-9.%-]+@[A-Z0-9.%-]+.[A-Z]{2,4}$/", trim($_POST['email'])))
使用preg_match.
因为在PHP> = 5.3中不推荐使用ereg_ *函数
另外对于电子邮件验证更好地使用filter_var
if (!filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL))
echo 'Email is incorrect';
标签:eregi,php 来源: https://codeday.me/bug/20190723/1510399.html