Alternative to eregi() in php [duplicate]

别来无恙 提交于 2019-12-21 20:35:56

问题


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'])))?

Any help is appreciated :)


回答1:


 if (!preg_match("/^[A-Z0-9.%-]+@[A-Z0-9.%-]+.[A-Z]{2,4}$/", trim($_POST['email'])))

Using preg_match.

Because ereg_* functions is deprecated in PHP >= 5.3

Also for email validation better used filter_var

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


来源:https://stackoverflow.com/questions/15046400/alternative-to-eregi-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!