Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn the text conversion hyperlink function:
This article uses.
Function urlToLink ($ str ){
$ Arr = array ("www." => "http: // www .");
$ Str = strtr ($ str, $ arr );
$ Arr = array ("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;
}
// Disconnects from a Chinese character
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;
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB