PHP automatically add a link to the URL method, the php URL link method
The example in this article describes how PHP automatically adds links to URLs. Share to everyone for your reference. The implementation method is as follows:
This automatically matches the URL in the page, including the http,ftp, and automatically adds a link to the URL.
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;} Use example: $text = "Welcome www.jb51.net:-)";p rint text2links ($text);
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1011255.html www.bkjia.com true http://www.bkjia.com/PHPjc/1011255.html techarticle PHP automatically add a link to the URL method, the PHP URL link method This article describes the PHP automatically to add a link to the URL method. Share to everyone for your reference. The concrete implementation method is as follows ...