使用preg_match函数的PHP错误 [英] PHP error using the preg_match function
本文介绍了使用preg_match函数的PHP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PHP eregi函数,但我注意到它已被弃用。这是我的代码:
I'm was using PHP eregi function, but I get the notice that it is deprecated. Here's my code:
!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))
因此,我试图用preg_match替换该函数,但似乎无法为preg_match获取正确的模式,因为以下代码出错:
Therefore I am trying to replace the function with the preg_match, but seems that I am unable to get the correct pattern for the preg_match, as I get error with the following code:
!preg_match("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))
这是我从上面的代码中得到的错误:
Here's the error I get from above code:
Warning: preg_match(): No ending delimiter '^' found in
感谢您的帮助。
推荐答案
您需要在正则表达式的开头和结尾使用定界符,通常是 /
:
You need to use a delimiter at the beginning and end of your regex, commonly /
:
!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/", trim($_POST['email']))
这篇关于使用preg_match函数的PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文