[英]Eregi() Deprecated php help?
I am recieving the error: 我收到错误:
Deprecated: Function eregi() is deprecated in C:\wamp\www\registration\class.register.php on line 75
with my code:: 用我的代码::
if(empty($this->email) || !eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email))
What alternative should I use and how can I implement it???? 我应该使用哪种替代方法,以及如何实施呢?
As @Sarfraz said ereg_*
functions are deprecated and you should use preg_*
instead. 正如@Sarfraz所说,不建议使用ereg_*
函数,而应使用preg_*
。 However in this case you shouldn't use regular expressions at all. 但是,在这种情况下,您根本不应使用正则表达式。 There is function called filter_var()
that allows you to validate some popular data formats (emails, URLs etc.) 有一个名为filter_var()
函数,该函数使您可以验证一些流行的数据格式(电子邮件,URL等)。
if (empty($this->email) || false == filter_var($this->email, FILTER_VALIDATE_EMAIL)) {
// Empty or not valid email
}
Yes ereg
family functions have been deprecated , you need to use preg
family functions instead. 是的, 不建议使用 ereg
系列功能,您需要改用preg
系列功能。 In your case, you should use preg_match
instead. 在您的情况下,应改用preg_match
。
That piece of code is equivalent to: 该段代码等效于:
if(empty($this->email) ||
!preg_match('~^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$~i',
$this->email))
It can also be compacted to: 它也可以压缩为:
if(empty($this->email) || !preg_match('~^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,4}$~i',
$this->email))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.