The PHP implementation uses the regular to convert the URLs in the text into linked tags,
Copy the Code code as follows:
function text2links ($str = ") {
if ($str = = "or!preg_match ('/(http|www\.| @)/I ', $str)) {return $str;}
$lines = explode ("\ n", $str); $new _text = ";
while (list ($k, $l) = each ($lines)) {
Replace Links:
$l = Preg_replace ("/([\t]|^) www\./i", "\\1http://www.", $l);
$l = Preg_replace ("/([\t]|^) ftp\./i", "\\1ftp://ftp.", $l);
$l = Preg_replace ("/(http:\/\/[^) \r\n!] +)/I ",
"\\1", $l);
$l = Preg_replace ("/(https:\/\/[^) \r\n!] +)/I ",
"\\1", $l);
$l = Preg_replace ("/(ftp:\/\/[^) \r\n!] +)/I ",
"\\1", $l);
$l = Preg_replace (
"/([-a-z0-9_]+ (\.[ _a-z0-9-]+) *@ ([A-z0-9-]+ (\.[ a-z0-9-]+) +))/I ",
"\\1", $l);
$new _text. = $l. " \ n ";
}
return $new _text;
}
http://www.bkjia.com/PHPjc/920971.html www.bkjia.com true http://www.bkjia.com/PHPjc/920971.html techarticle The PHP implementation uses the regular to convert the URL in the text into a link tag, copying the code as follows: function text2links ($str = ") {if ($str = =" or!preg_match ('/(http|www\.| @)/I ', $str) ...