Php code for converting a php url to a hyperlink
// Convert the message to the URL function strtr_str_to_url ($ str) {$ arr = array ("www." =>" http://www . "); $ Str = strtr ($ str, $ arr); $ arr = array (" http://http:// "=>" Http: // "); $ str = strtr ($ str, $ arr); $ str2 = explode (" http: // ", $ str ); for ($ n = 1; isset ($ str2 [$ n]); $ n ++) {$ str3 = explode (". ", $ str2 [$ n]); if (isset ($ str3 [1]) {$ str4 = explode (" www. ", $ str2 [$ n]); if (isset ($ str4 [1]) & isset ($ str3 [2]) |! Isset ($ str4 [1]) {$ length = strlen ($ str2 [$ n]); for ($ I = 0; $ I <= $ length; $ I ++) {// disconnect from space if ($ I-1) = strlen (trim (mb_substr ($ str2 [$ n], 0, $ I, 'gb2312') {$ ii = $ I-1; $ url1 = mb_substr ($ str2 [$ n], 0, $ ii, 'gb2312 '); $ url2 = mb_substr ($ str2 [$ n], $ ii, $ length, 'gb2312'); $ url3 = "http ://". $ url1 ."". $ url2; break;} // disconnect if ($ I! = Strlen (mb_substr ($ str2 [$ n], 0, $ I, 'gb2312') {$ ii = $ I-1; $ url1 = mb_substr ($ str2 [$ n], 0, $ ii, 'gb2312'); $ url2 = mb_substr ($ str2 [$ n], $ ii, $ length, 'gb2312'); $ url3 = "http ://". $ url1 ."". $ url2; break;} if ($ I = $ length) $ url3 = "http ://". $ str2 [$ n]. "" ;}} else $ url3 = "http ://". $ str2 [$ n];} else $ url3 = "http ://". $ str2 [$ n]; $ url. = $ url3;} if (substr ($ str, 0,7) = "http: //") $ url = "". $ str2 [0]. "". $ url; else $ url = $ str2 [0]. $ url; return $ url ;}
2.
[Code][PHP] code
$ Str = "http: // 127.0.0.1/test/str_to_url.php? Id = 1 2 is http: // 127.0.0.1/test/str_to_url.php http: // 127.0.0.1/test/str_to_url.php is
Http: // 127.0.0.1/test/str_to_url.php
Http: // 127.0.0.1/test/str_to_url.php
Http://www.baidu.com/homego
Http://www.baidu.com/homecai
Www.baidu.com/homewww.baidu.com/home's
Www.baidu.com/home's
Www. baiducom/home
Http://www.baiducom/homecai "; $ str2 = strtr_msg_to_url ($ str); echo" $ str2 ";