Есть ли в Fuelphp auto_link()?

Извините за это, но мне очень нужна эта функция, я не смог найти ее ни в документах, ни в Google. Есть ли в Fuel PHP функция auto_link(), как в codeigniter?


person Side    schedule 26.08.2012    source источник


Ответы (1)


Сделай сам, вот функция, которую использует CodeIgniter:

url_helper.php строка 380.

function auto_link($str, $type = 'both', $popup = FALSE)
{
    if ($type != 'email')
    {
        if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
        {
            $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";

            for ($i = 0; $i < count($matches['0']); $i++)
            {
                $period = '';
                if (preg_match("|\.$|", $matches['6'][$i]))
                {
                    $period = '.';
                    $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
                }

                $str = str_replace($matches['0'][$i],
                                    $matches['1'][$i].'<a href="http'.
                                    $matches['4'][$i].'://'.
                                    $matches['5'][$i].
                                    $matches['6'][$i].'"'.$pop.'>http'.
                                    $matches['4'][$i].'://'.
                                    $matches['5'][$i].
                                    $matches['6'][$i].'</a>'.
                                    $period, $str);
            }
        }
    }

    if ($type != 'url')
    {
        if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
        {
            for ($i = 0; $i < count($matches['0']); $i++)
            {
                $period = '';
                if (preg_match("|\.$|", $matches['3'][$i]))
                {
                    $period = '.';
                    $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
                }

                $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
            }
        }
    }

    return $str;
}
person Sergey Telshevsky    schedule 26.08.2012