Last active
December 17, 2015 11:39
-
-
Save RalfAlbert/5604214 to your computer and use it in GitHub Desktop.
Test WordPress' is_email() and sanitize_email() functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require wordpress | |
/** | |
* @see http://en.wikipedia.org/wiki/Email_address | |
*/ | |
$email = array(); | |
$email[] = 'john.smith(commentedemail)@example.com'; | |
$email[] = '(commentedemail)[email protected]'; | |
$email[] = 'john.smith@(commentedemail)example.com'; | |
$email[] = '[email protected](commentedemail)'; | |
$email[] = 'john.smith(commented email)@example.com'; | |
$email[] = '(commented email)[email protected]'; | |
$email[] = 'john.smith@(commented email)example.com'; | |
$email[] = '[email protected](commented email)'; | |
array_walk( | |
$email, | |
function($e){ printf('%s -> %s / %s<br>',$e, true==is_email($e)?'yes':'no', sanitize_email($e) ); } | |
); | |
/* | |
* Output | |
*/ | |
/* | |
john.smith(commentedemail)@example.com -> no / [email protected] | |
(commentedemail)[email protected] -> no / [email protected] | |
john.smith@(commentedemail)example.com -> no / [email protected] | |
[email protected](commentedemail) -> no / [email protected] | |
john.smith(commented email)@example.com -> no / [email protected] | |
(commented email)[email protected] -> no / [email protected] | |
john.smith@(commented email)example.com -> no / [email protected] | |
[email protected](commented email) -> no / [email protected] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment