PHP implementation uses regular to convert URLs in text into linked tags, _php tutorial

Source: Internet
Author: User

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) ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.