本文介绍了FILTER_VALIDATE_EMAIL的一致性如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例有效的电子邮件地址:

PHP代码:

 <?php 
标题('Content-Type:text / plain');

$ email ='这是一个有效的地址@ example.com;
$ checked = filter_var($ email,FILTER_VALIDATE_EMAIL);
var_dump($ email,$ checked);

在一台服务器上输出:(PHP版本5.2.6):

phpinfo()

 启用输入验证和过滤
修订版$修订:1.52.2.42 $

指令本地值主值
filter.default unsafe_raw unsafe_raw
filter.default_flags无值无值

另一个服务器上的输出(PHP 5.3.3版):

phpinfo() / code>:

 启用输入验证和过滤
修订版$修订:298196 $

指令本地值主值
filter.default unsafe_raw unsafe_raw
filter.default_flags无值无值
/ pre>

我看不到任何上看到使用过滤器 FILTER_VALIDATE_EMAIL 不一致!



输出为PHP 5.2.0,5.2.14 - 5.2.17,5.3.3 - 5.3.18,5.4.0 - 5.4.8

  string(37)这是一个有效的地址@ example.com
bool(false)

和5.2.1 - 5.2。 13,5.3.0 - 5.3.2

  string(37)这是一个有效的地址@ example.com 
string(37)这是一个有效的地址@ example.com

令人惊奇的是,它工作在5.2.0但不是5.2.1-5.2.13,然后再次为5.2.14 !!!



Btw 是检查所有可用PHP版本的这种行为更改的极好资源。



有,包括术语FILTER_VALIDATE_EMAIL,但没有一个似乎匹配您的错误。您可以将其添加到 ...


Sample valid e-mail address:

PHP code:

<?php
header('Content-Type: text/plain');

$email = '"this is a valid address"@example.com';
$checked = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($email, $checked);

Output on one server: (PHP Version 5.2.6):

phpinfo():

Input Validation and Filtering      enabled
Revision                            $Revision: 1.52.2.42 $

Directive             Local Value   Master Value
filter.default        unsafe_raw    unsafe_raw
filter.default_flags  no value      no value

Output on another server (PHP Version 5.3.3):

phpinfo():

Input Validation and Filtering      enabled
Revision                            $Revision: 298196 $

Directive             Local Value   Master Value
filter.default        unsafe_raw    unsafe_raw
filter.default_flags  no value      no value

I cannot see anything in the documentation to suggest that this has changed, so perhaps it's some other configuration setting.

解决方案

As you can see on http://3v4l.org/vKONS the usage of the filter FILTER_VALIDATE_EMAIL it is not consistent!

http://3v4l.org/vKONS outputs for PHP 5.2.0, 5.2.14 - 5.2.17, 5.3.3 - 5.3.18, 5.4.0 - 5.4.8

string(37) ""this is a valid address"@example.com" 
bool(false)

and for 5.2.1 - 5.2.13, 5.3.0 - 5.3.2

string(37) ""this is a valid address"@example.com" 
string(37) ""this is a valid address"@example.com"

It is remarkable that it worked for 5.2.0 but not 5.2.1-5.2.13 and then again for 5.2.14!!!

Btw 3v4l.org is a great resource to check such behavior changes across all available PHP versions.

There are several bugs open including the term FILTER_VALIDATE_EMAIL, but none seems to match your kind of error. You might add it to the PHP bugtracker...

这篇关于FILTER_VALIDATE_EMAIL的一致性如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 16:50