Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
Last active December 17, 2015 11:39
Show Gist options
  • 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)[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