public static function replaceLinksInTextsWithHrefs(string $text): string
    {
        $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);

        $ret = ' ' . $text;

        // Replace links with http://
        $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);

        // Replace links without http://
        $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);

        // Replace email addresses
        $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
        $ret = substr($ret, 1);

        return $ret;
    }
public static function replaceLinksInTextsWithHrefs(string $text): string
    {
        $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);

        $ret = ' ' . $text;

        // Replace links with http://
        $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);

        // Replace links without http://
        $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);

        // Replace email addresses
        $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
        $ret = substr($ret, 1);

        return $ret;
    }
public static function replaceLinksInTextsWithHrefs ( string $ text ) : string { $ text = preg_replace ( '#(script|about|applet|activex|chrome):#is' , "\\1:" , $ text ) ; $ ret = ' ' . $ text ; // Replace links with http:// $ ret = preg_replace ( "#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is" , "\\1<a href=\"\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>" , $ ret ) ; // Replace links without http:// $ ret = preg_replace ( "#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is" , "\\1<a href=\"http://\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>" , $ ret ) ; // Replace email addresses $ ret = preg_replace ( "#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i" , "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>" , $ ret ) ; $ ret = substr ( $ ret , 1 ) ; return $ ret ; }
Returns same text with changed link word to full hrefs

@param string $text

@return string
Returns same text with changed link word to full hrefs