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)john.smith@example.com'; | |
$email[] = 'john.smith@(commentedemail)example.com'; | |
$email[] = 'john.smith@example.com(commentedemail)'; | |
$email[] = 'john.smith(commented email)@example.com'; | |
$email[] = '(commented email)john.smith@example.com'; | |
$email[] = 'john.smith@(commented email)example.com'; | |
$email[] = 'john.smith@example.com(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 / john.smithcommentedemail@example.com | |
(commentedemail)john.smith@example.com -> no / commentedemailjohn.smith@example.com | |
john.smith@(commentedemail)example.com -> no / john.smith@commentedemailexample.com | |
john.smith@example.com(commentedemail) -> no / john.smith@example.comcommentedemail | |
john.smith(commented email)@example.com -> no / john.smithcommentedemail@example.com | |
(commented email)john.smith@example.com -> no / commentedemailjohn.smith@example.com | |
john.smith@(commented email)example.com -> no / john.smith@commentedemailexample.com | |
john.smith@example.com(commented email) -> no / john.smith@example.comcommentedemail | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment