Função PHP que detecta links no formato de texto e transforma em links HTML
Função PHP que detecta um link em formato de texto e transforma o link no formato HTML. function identifyLinkInString($string){ if(!is_string($string)){ return $string; } $expression = “/((http|https|ftp|ftps):\/\/(www\.|.*?\/)?|www\.)([a-zA-Z0-9]|_|-)+(\.(([0-9a-zA-Z]|-|_|\/|\?|=|&|&|&)+))+/i”; preg_match_all($expression, $string, $match); foreach($match[0] AS $search_link_text){ /** * Insert http:// if not exists */ $link_text_origin = $search_link_text; if(stristr($search_link_text, “http://”) === false && stristr($search_link_text, “https://”) === false){ $link = “http://” . $search_link_text; }else{ $link = $search_link_text; } $link_lenght = strlen($link_text_origin); $link_name = str_replace([‘&’,’&’], [‘&’,’&’], $link); $string = str_ireplace ($link_text_origin, ‘<a href=”‘.$link.'” target=”_blank”>’.(($link_lenght > 60) ? substr ($link_name, 0, 25). “…”. Continue→