CBPTaskResult :: ConvertBCodeAnchorTag: Bitrix method

      
<?php 
//  CBPTaskResult :: ConvertBCodeAnchorTag()
//  /dist/bitrix/modules/bizproc/classes/general/taskservice.php:837

    
function ConvertBCodeAnchorTag($url$text '')
    {
        if (
is_array($url))
        {
            
$text = isset($url[2]) ? $url[2] : $url[1];
            
$url $url[1];
        }

        
$result "";

        if (
$url === $text)
        {
            
$arUrl explode(", "$url);
            
$arText $arUrl;
        }
        else
        {
            
$arUrl = array($url);
            
$arText = array($text);
        }

        for (
$i 0$n count($arUrl); $i $n$i++)
        {
            
$url $arUrl[$i];
            
$text $arText[$i];

            
$text str_replace("\\\"""\""$text);
            
$end "";

            if (
preg_match("/([\.,\?]|&#33;)$/".BX_UTF_PCRE_MODIFIER$url$match))
            {
                
$end $match[1];
                
$url preg_replace("/([\.,\?]|&#33;)$/".BX_UTF_PCRE_MODIFIER""$url);
                
$text preg_replace("/([\.,\?]|&#33;)$/".BX_UTF_PCRE_MODIFIER""$text);
            }

            
$url preg_replace(
                array(
"/&amp;/".BX_UTF_PCRE_MODIFIER"/javascript:/i".BX_UTF_PCRE_MODIFIER),
                array(
"&""java script&#58; "),
                
$url
            
);
            if (
substr($url01) != "/" && !preg_match("/^(http|news|https|ftp|aim|mailto)\:\/\//i".BX_UTF_PCRE_MODIFIER$url))
                
$url 'http://'.$url;
            if (!
preg_match("/^((http|https|news|ftp|aim):\/\/[-_:[email protected]]+)*([^\"\'])+$/i".BX_UTF_PCRE_MODIFIER$url))
                return 
$text." (".$url.")".$end;

            
$text preg_replace(
                array(
"/&amp;/i".BX_UTF_PCRE_MODIFIER"/javascript:/i".BX_UTF_PCRE_MODIFIER),
                array(
"&""javascript&#58; "),
                
$text
            
);

            if (
$result !== "")
                
$result .= ", ";

            
$result .= "<a href=\"".$url."\" target='_blank'>".$text."</a>".$end;
        }

        return 
$result;
    }