Hello HashCode! Tell me how you can turn the link into text: http://google.com on
<a href = "http://google.com"> http://google.com </a>
I tried using str_replace (text); but the fact is that in addition to the link, there may be just a text.
http://google.c...">
Hello HashCode! Tell me how you can turn the link into text: http://google.com on
<a href = "http://google.com"> http://google.com </a>
I tried using str_replace (text); but the fact is that in addition to the link, there may be just a text.
$переменная_с_текстом = preg_replace("#(https?|ftp)://\S+[^\s.,> )\];'\"!?]#",'<a href="\\0">\\0</a>',$переменная_с_текстом);
I think it would be better:
$site = "http://google.com"; $pattern = "/^((https?|ftp)\:\/\/)?([a-z0-9]{1})((\.[a-z0-9-])|([a-z0-9-]))*\.([az]{2,6})(\/?)$/"; $replace = "<a href=\"\\0\">\\0</a>"; $result = preg_replace($pattern, $replace, $site); echo $result;
It's so simple that it’s already funny
When you enter the line "Hi this my site: site.net", it displays "Hi this my site: site.net ";
function s_link ($text){ $arrt = array(); $arrt = explode(" ", $text); $dot; for($i=0;$i<count($arrt);$i++){ if(strpos($arrt[$i],".")){ $dot .= "<a href='http://".$arrt[$i]."'>".$arrt[$i]."</a> "; }else{ $dot .= $arrt[$i]." "; } } return $dot; }
Source: https://ru.stackoverflow.com/questions/227378/
All Articles