替代php中的eregi() [英] Alternative to eregi() in php

查看:183
本文介绍了替代php中的eregi()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在邮件脚本中使用了eregi,但是最近,我收到了该功能已过时的错误消息.

So, i was using eregi in my mail script, but as of lately, i get the error that the function is deprecated.

因此,替换以下代码的最简单方法是:

So, what is the easiest way to replace the following bit of code:

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.

Using preg_match.

因为ereg_ *函数已在PHP> = 5.3中弃用

Because ereg_* functions is deprecated in PHP >= 5.3

为了更好地进行电子邮件验证,还使用了 filter_var

Also for email validation better used filter_var

if (!filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL))
    echo 'Email is incorrect';

这篇关于替代php中的eregi()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆