Skip to content

Instantly share code, notes, and snippets.

@shelbyKiraM
Created November 28, 2010 06:06
Show Gist options
  • Save shelbyKiraM/718649 to your computer and use it in GitHub Desktop.
Save shelbyKiraM/718649 to your computer and use it in GitHub Desktop.
/**
* breakapart
*
* @return array
* @author Shelby Munsch
**/
function breakapart(string $combinedstring)
{
$return = array("name", "email");
// match only the email address
$email = preg_match("[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}", $combinedstring);
// strips the email address and any left over quotes from the string. what's left should be just the name
$name = preg_replace("\"", "", preg_replace("(<)?[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}(>)?", "", $combinedstring));
$return['name'] = $name;
$return['email'] = $email;
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment