phantom007 — 2013-08-14T07:07:10-04:00 — #1
Please consider the following code:
Ideally the above email should be invalid and var_dump should return false but the strange thing is when u run this code on the following sites they return non similar results, can anyone tell me whats going on?
cpradio — 2013-08-14T07:26:17-04:00 — #2
This seems familiar. First off, the two sites are running two different versions of PHP. codepad is running 5.2.5, and writecodeonline is running 5.4.15
I believe there was a change/correction to the filter_validate_email between these versions to better match the RFC standards. I'll have to find that thread here on sitepoint.
phantom007 — 2013-08-14T07:50:06-04:00 — #3
how did u figure that out?
cpradio — 2013-08-14T07:56:35-04:00 — #4
I put var_dump(phpversion()); in each one to see what it outputted
cpradio — 2013-08-14T08:01:55-04:00 — #5
More information about when FILTER_VALIDATE_EMAIL was updated, it was in 5.3.3 (http://www.php.net/ChangeLog-5.php, search for "FILTER_VALIDATE_EMAIL filter needs updating") and 5.2.14 (so codepad is running an old version of FILTER_VALIDATE_EMAIL), writecodeonline is running the latest change to that constant.
Hope that helps
phantom007 — 2013-08-14T08:42:31-04:00 — #6
oh ok, nice piece of info..thansk for sharing..
force — 2013-08-14T15:23:31-04:00 — #7
The php email filter doesn't follow the RFC for email addresses in all versions of php. Ever since I found that out, I've been using my own regex filter for email addresses.
I've managed email lists in the past, so I've seen all sorts of wacky email address formats that were valid according to the RFC, but many websites wouldn't accept them because of the limitations of their validation functions.
This is a little overly complex for just validating an email address, but I reuse portions of this for other things.
define('DELIM_S', "\\x02"); //starting delimiter
define('DELIM_E', "\\x02u"); //ending delimiter
* converts number to boolean
* @param string|int $num
* @return bool
return (is_numeric($num) && $num>0) ? true : false;
* validates an email address
* @param string $mail
* @param bool
/* start procedural scripting here */
$email = "firstname.lastname@example.org";
echo 'The email is valid';
echo 'The email is not valid';