protected function linkifyEmails($text, $options = array('attr' => ''))
    {
        $pattern = '~(?xi)
                \b
                (?<!=)           # Not part of a query string
                [A-Z0-9._\'%+-]+ # Username
                @                # At
                [A-Z0-9.-]+      # Domain
                \.               # Dot
                [A-Z]{2,4}       # Something
        ~u';

        $callback = function ($match) use ($options) {
            if (isset($options['callback'])) {
                $cb = $options['callback']($match[0], $match[0], true);
                if (!is_null($cb)) {
                    return $cb;
                }
            }

            return '<a href="mailto:' . $match[0] . '"' . $options['attr'] . '>' . $match[0] . '</a>';
        };

        return preg_replace_callback($pattern, $callback, $text);
    }
protected function linkifyEmails($text, $options = array('attr' => ''))
    {
        $pattern = '~(?xi)
                \b
                (?<!=)           # Not part of a query string
                [A-Z0-9._\'%+-]+ # Username
                @                # At
                [A-Z0-9.-]+      # Domain
                \.               # Dot
                [A-Z]{2,4}       # Something
        ~u';

        $callback = function ($match) use ($options) {
            if (isset($options['callback'])) {
                $cb = $options['callback']($match[0], $match[0], true);
                if (!is_null($cb)) {
                    return $cb;
                }
            }

            return '<a href="mailto:' . $match[0] . '"' . $options['attr'] . '>' . $match[0] . '</a>';
        };

        return preg_replace_callback($pattern, $callback, $text);
    }
protected function linkifyEmails ( $ text , $ options = array ( 'attr' => '' ) ) { $ pattern = '~(?xi)
                \b
                (?<!=)           # Not part of a query string
                [A-Z0-9._\'%+-]+ # Username
                @                # At
                [A-Z0-9.-]+      # Domain
                \.               # Dot
                [A-Z]{2,4}       # Something
        ~u' ; $ callback = function ( $ match ) use ( $ options ) { if ( isset ( $ options [ 'callback' ] ) ) { $ cb = $ options [ 'callback' ] ( $ match [ 0 ] , $ match [ 0 ] , true ) ; if ( ! is_null ( $ cb ) ) { return $ cb ; } } return '<a href="mailto:' . $ match [ 0 ] . '"' . $ options [ 'attr' ] . '>' . $ match [ 0 ] . '</a>' ; } ; return preg_replace_callback ( $ pattern , $ callback , $ text ) ; }
Add HTML links to email addresses in plain text.

@param string $text    Text to linkify.
@param array  $options Options, 'attr' key being the attributes to add to the links, with a preceding space.

@return string Linkified text.
Add HTML links to email addresses in plain text .