Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
Last active December 17, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RalfAlbert/5604214 to your computer and use it in GitHub Desktop.
Save RalfAlbert/5604214 to your computer and use it in GitHub Desktop.
Test WordPress' is_email() and sanitize_email() functions
<?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