src/sb/Text/Bling.php
public static function linksToHtml($str, $allow_email=false, $link_markup=null)
    {

        ### Convert Email Tags ###
        if(!$allow_email){
            $str = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", '<b> \\2 AT \\3 </b>', $str);
        } else {
            $str = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", ' <a href="mailto:\\2@\\3">\\2@\\3</a>', $str);
        }

        ### phrase links ###
        $str = preg_replace( "~\[(?:url|link)=(http.*?)\](.*?)\[\/(?:url|link)\]~", "<a class=\"blank\" href=\"\\1\">\\2</a>", $str);

        $link = $link_markup ? $link_markup : '(LINK)';
        ### url links ###\\2://\\3
        //$str = preg_replace("#(\s|\n)([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", ' <a href="\\2://\\3" title="\\2://\\3">'.$link.'</a>', $str);

        $str = preg_replace_callback("#(^|\s)([a-z]+?://[\w\-\.,\?!%\*\#:;~\\&$@\/=\+]+)#i", function($match) use($link){
            $href = $match[2];
            $end_punct = '';

            if(preg_match("~[\.\?\!]$~", $href, $matchx)){
                $end_punct = $matchx[0];
                $href = substr($href,0,-1);
            }
            return $match[1].'<a href="'.$href.'" title="'.$href.'">'.$link.'</a>'.$end_punct;
        }, $str);

        return $str;
    }
public static function linksToHtml($str, $allow_email=false, $link_markup=null)
    {

        ### Convert Email Tags ###
        if(!$allow_email){
            $str = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", '<b> \\2 AT \\3 </b>', $str);
        } else {
            $str = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", ' <a href="mailto:\\2@\\3">\\2@\\3</a>', $str);
        }

        ### phrase links ###
        $str = preg_replace( "~\[(?:url|link)=(http.*?)\](.*?)\[\/(?:url|link)\]~", "<a class=\"blank\" href=\"\\1\">\\2</a>", $str);

        $link = $link_markup ? $link_markup : '(LINK)';
        ### url links ###\\2://\\3
        //$str = preg_replace("#(\s|\n)([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", ' <a href="\\2://\\3" title="\\2://\\3">'.$link.'</a>', $str);

        $str = preg_replace_callback("#(^|\s)([a-z]+?://[\w\-\.,\?!%\*\#:;~\\&$@\/=\+]+)#i", function($match) use($link){
            $href = $match[2];
            $end_punct = '';

            if(preg_match("~[\.\?\!]$~", $href, $matchx)){
                $end_punct = $matchx[0];
                $href = substr($href,0,-1);
            }
            return $match[1].'<a href="'.$href.'" title="'.$href.'">'.$link.'</a>'.$end_punct;
        }, $str);

        return $str;
    }
public static function linksToHtml ( $ str , $ allow_email = false , $ link_markup = null ) { ### Convert Email Tags ### if ( ! $ allow_email ) { $ str = preg_replace ( "#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i" , '<b> \\2 AT \\3 </b>' , $ str ) ; } else { $ str = preg_replace ( "#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i" , ' <a href="mailto:\\2@\\3">\\2@\\3</a>' , $ str ) ; } ### phrase links ### $ str = preg_replace ( "~\[(?:url|link)=(http.*?)\](.*?)\[\/(?:url|link)\]~" , "<a class=\"blank\" href=\"\\1\">\\2</a>" , $ str ) ; $ link = $ link_markup ? $ link_markup : '(LINK)' ; ### url links ###\\2://\\3 //$str = preg_replace("#(\s|\n)([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", ' <a href="\\2://\\3" title="\\2://\\3">'.$link.'</a>', $str); $ str = preg_replace_callback ( "#(^|\s)([a-z]+?://[\w\-\.,\?!%\*\#:;~\\&$@\/=\+]+)#i" , function ( $ match ) use ( $ link ) { $ href = $ match [ 2 ] ; $ end_punct = '' ; if ( preg_match ( "~[\.\?\!]$~" , $ href , $ matchx ) ) { $ end_punct = $ matchx [ 0 ] ; $ href = substr ( $ href , 0 , - 1 ) ; } return $ match [ 1 ] . '<a href="' . $ href . '" title="' . $ href . '">' . $ link . '</a>' . $ end_punct ; } , $ str ) ; return $ str ; }
Converts email and http links to HTML links

@param string $str
@return string
Converts email and http links to HTML links