<?
// validate email address
function validate_email( $email ){
return (filter_var($email, FILTER_VALIDATE_EMAIL)) ? true : false;
}
// split email into name / address
function email_split( $str ){
$sPattern = "/([\w\s\'\"]+[\s]+)?(<)?(([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4}))?(>)?/g";
preg_match($sPattern,$str,$aMatch);
$name = (isset($aMatch[1])) ? $aMatch[1] : '';
$email = (isset($aMatch[3])) ? $aMatch[3] : '';
return array( 'name'=>trim($name), 'email'=>trim($email) );
}
// test it
$tests = array(
'person@place.com',
'monarch <themonarch@tgoci.com>',
'blahblah',
"'doc venture' <doc@venture.com>"
);
foreach ($tests as $test){
echo print_r( email_split($test), true );
}
?>