为什么PHP filter_var会说这是一个有效的电子邮件地址? [英] Why does PHP filter_var say that this is a valid email address?

查看:99
本文介绍了为什么PHP filter_var会说这是一个有效的电子邮件地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户注册到我的网站时,我使用 filter_var PHP函数来验证电子邮件地址。

I use the filter_var PHP function to validate email address when a user signs up to my site.

我在帖子中使用以下代码:

I use this code from the post:

$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);

然后再做:

if(!$email) {
  // return to the form 
}
else {
  // send registration info
}

现在当我 var_dump($ email) ,我得到输出:

now when I var_dump($email), I get the output:

string(23) "user."name"@example.com"

我想知道为什么它不返回false。我认为双引号是不可接受的,那么PHP为什么说它是有效的?

I would like to know why this does not return false. I think the double quotes are not acceptable, so why does PHP say it’s valid?

推荐答案

有效的电子邮件地址


加引号的字符串可能以点分隔的形式存在于
本地部分中,或者当最外面的引号是本地部分的最外面
个字符时可能存在(例如,允许abc。 defghi .xyz @ example.com或
abcdefghixyz @ example.com。abc defghi xyz@example.com不允许
; abc neither也不可以) def\ ghi@example.com)。

A quoted string may exist as a dot separated entity within the local-part or it may exist when the outermost quotes are the outermost chars of the local-part (e.g. abc."defghi".xyz@example.com or "abcdefghixyz"@example.com are allowed. abc"defghi"xyz@example.com is not; neither is abc\"def\"ghi@example.com).

这篇关于为什么PHP filter_var会说这是一个有效的电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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