1
Works for several links but if I put the same 2x link in the string does not work as do?
function MontarLink($texto)
{
if (!is_string ($texto))
return $texto;
$er = "/(https:\/\/(www\.|.*?\/)?|http:\/\/(www\.|.*?\/)?|www\.)([a-zA-Z0-9]+|_|-)+(\.(([0-9a-zA-Z]|-|_|\/|\?|=|&)+))+/i";
preg_match_all ($er, $texto, $match);
foreach ($match[0] as $link)
{
//coloca o 'http://' caso o link não o possua
$link_completo = (stristr($link, "http") === false) ? "http://" . $link : $link;
$link_len = strlen ($link);
//troca "&" por "&", tornando o link válido pela W3C
$web_link = str_replace ("&", "&", $link_completo);
$texto = str_ireplace ($link, "<a href=\"" . strtolower($web_link) . "\" target=\"_blank\">". (($link_len > 60) ? substr ($web_link, 0, 25). "...". substr ($web_link, -15) : $web_link) ."</a>", $texto);
}
return $texto;
}
echo MontarLink("ola mundo www.cade.com.br"); // ESSE FUNCIONA!!!
echo "<br><br>";
echo MontarLink("ola mundo www.cade.com.br outro site www.terra.com.br "); // ESSE FUNCIONA!!!
echo "<br><br>";
echo MontarLink("ola mundo www.cade.com.br mesmo site www.cade.com.br"); // NÃO FUNCIONA!!!
COTD:
//troca "&" por "&", tornando o link válido pela W3C
– Bacco
@bfavaretto Poxa... I’m talking about the same string guys... echo Montarlink("ola mundo www.cade.com.br --- second site www.cade.com.br third site www.cade.com.br");
– Israel
It actually seems to be working yes: http://ideone.com/pxSws9
– bfavaretto
@bfavaretto guy looks that sinister!!! I found the error.. the error is if it is 2 links equal!!! I put here 2 different links and it worked.. but with 2 equal links he of the stick... for it will be?
– Israel
I made some edits in the code to facilitate... see at the end the 3 echo.
– Israel
Mark one of the answers as accepted. Your problem today may be someone’s tomorrow and have an answer marked as accepted help in the decision.
– Bruno Augusto