public static function parse($string)
    {
        $userId  = new Crypt_GPG_UserId();
        $name    = '';
        $email   = '';
        $comment = '';

        // get email address from end of string if it exists
        $matches = array();
        if (preg_match('/^(.*?)<([^>]+)>$/', $string, $matches) === 1) {
            $string = trim($matches[1]);
            $email  = $matches[2];
        }

        // get comment from end of string if it exists
        $matches = array();
        if (preg_match('/^(.+?) \(([^\)]+)\)$/', $string, $matches) === 1) {
            $string  = $matches[1];
            $comment = $matches[2];
        }

        // there can be an email without a name
        if (!$email && preg_match('/^[\S]+@[\S]+$/', $string, $matches) === 1) {
            $email = $string;
        } else {
            $name = $string;
        }

        $userId->setName($name);
        $userId->setComment($comment);
        $userId->setEmail($email);

        return $userId;
    }
public static function parse($string)
    {
        $userId  = new Crypt_GPG_UserId();
        $name    = '';
        $email   = '';
        $comment = '';

        // get email address from end of string if it exists
        $matches = array();
        if (preg_match('/^(.*?)<([^>]+)>$/', $string, $matches) === 1) {
            $string = trim($matches[1]);
            $email  = $matches[2];
        }

        // get comment from end of string if it exists
        $matches = array();
        if (preg_match('/^(.+?) \(([^\)]+)\)$/', $string, $matches) === 1) {
            $string  = $matches[1];
            $comment = $matches[2];
        }

        // there can be an email without a name
        if (!$email && preg_match('/^[\S]+@[\S]+$/', $string, $matches) === 1) {
            $email = $string;
        } else {
            $name = $string;
        }

        $userId->setName($name);
        $userId->setComment($comment);
        $userId->setEmail($email);

        return $userId;
    }
public static function parse ( $ string ) { $ userId = new Crypt_GPG_UserId ( ) ; $ name = '' ; $ email = '' ; $ comment = '' ; // get email address from end of string if it exists $ matches = array ( ) ; if ( preg_match ( '/^(.*?)<([^>]+)>$/' , $ string , $ matches ) === 1 ) { $ string = trim ( $ matches [ 1 ] ) ; $ email = $ matches [ 2 ] ; } // get comment from end of string if it exists $ matches = array ( ) ; if ( preg_match ( '/^(.+?) \(([^\)]+)\)$/' , $ string , $ matches ) === 1 ) { $ string = $ matches [ 1 ] ; $ comment = $ matches [ 2 ] ; } // there can be an email without a name if ( ! $ email && preg_match ( '/^[\S]+@[\S]+$/' , $ string , $ matches ) === 1 ) { $ email = $ string ; } else { $ name = $ string ; } $ userId -> setName ( $ name ) ; $ userId -> setComment ( $ comment ) ; $ userId -> setEmail ( $ email ) ; return $ userId ; }
Parses a user id object from a user id string

A user id string is of the form:
<b><kbd>name (comment) <email-address></kbd></b> with the <i>comment</i>
and <i>email-address</i> fields being optional.

@param string $string the user id string to parse.

@return Crypt_GPG_UserId the user id object parsed from the string.
Parses a user id object from a user id string