0

我有用户的 php 邮件表单,升级后出现此错误:

已弃用:函数 eregi() 已弃用

这是检查电子邮件是否有效的代码行:

if(trim($_POST['COTB_05']) == '') {$hasError = true;} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['COTB_05']))) {$hasError = true;} else {$COTB_05 = trim($_POST['COTB_05']);}

试图将eregi更改为preg_match

if(trim($_POST['COTB_05']) == '') {$hasError = true;} else if (!preg_match("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['COTB_05']))) {$hasError = true;} else {$COTB_05 = trim($_POST['COTB_05']);}

但又出现了一个错误:

警告:preg_match() [function.preg-match]:在第 4 行的 W:\domains\localhost\content\email_cotb.php 中找不到结束分隔符 '^'

修复: 忘记使用/i

!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/i"

所以这不是区分大小写的:)

4

0 回答 0