<?PHP/** * text path converted to linked text * @param string $str Convert content * @return string*/functionUrltolink ($str) { $arr=Array("www." = "http://www".)); $str=STRTR($str,$arr); $arr=Array("http://http://" = "//"); $str=STRTR($str,$arr); $str 2=Explode("/http",$str); for($n= 1;isset($str 2[$n]);$n++) { $STR 3=Explode(".",$str 2[$n]); if(isset($STR 3[1])) { $STR 4=Explode("www.",$str 2[$n]); if((isset($STR 4[1]) &&isset($STR 3[2])) | | !isset($STR 4[1])) { $length=strlen($str 2[$n]); for($i= 0;$i<=$length;$i++) { //Break from Space if(($i-1) = =strlen(Trim(Mb_substr ($str 2[$n], 0,$i, ' gb2312 ')))) { $ii=$i-1; $url 1= Mb_substr ($str 2[$n], 0,$ii, ' gb2312 '); $url 2= Mb_substr ($str 2[$n],$ii,$length, ' gb2312 '); $url 3= "<a href=\" http://".$url 1. "\" target=\ "_blank\" >http://".$url 1. "</a>".$url 2; Break; } //disconnect from the occurrence of kanji if($i!=strlen(Mb_substr ($str 2[$n], 0,$i, ' gb2312 '))) { $ii=$i-1; $url 1= Mb_substr ($str 2[$n], 0,$ii, ' gb2312 '); $url 2= Mb_substr ($str 2[$n],$ii,$length, ' gb2312 '); $url 3= "<a href=\" http://".$url 1. "\" target=\ "_blank\" >http://".$url 1. "</a>".$url 2; Break; } if($i==$length) $url 3= "<a href=\" http://".$str 2[$n] . "\" target=\ "_blank\" >http://".$str 2[$n] . "</a>"; } } Else $url 3= "http://".$str 2[$n]; } Else $url 3= "http://".$str 2[$n]; $url.=$url 3; } if(substr($str, 0, 7) = = "http//") $url= "<a href=\"/http$str 2[0]\ "target=\" _blank\ ">".$str 2[0]. "</a>".$url; Else $url=$str 2[0].$url; return $url; }?>
PHP text path converted to linked text