Home >Backend Development >PHP Tutorial >Use PHP to convert a URL string into a hyperlink (website or email)_PHP tutorial

Use PHP to convert a URL string into a hyperlink (website or email)_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:37:491012browse

Copy code The code is as follows:

function makeClickableLinks($text) {
$text = eregi_replace('(((f| ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '1< /a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+. ~#?&//=]+)','1
2', $text);
$text = eregi_replace('([_ .0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})', '1', $text);
return $text;
}

Implementation principle:
mainly uses the regular principle to match URL characters or Email to replace it with a hyperlink.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321874.htmlTechArticleCopy the code The code is as follows: function makeClickableLinks($text) { $text = eregi_replace('(((f|ht ){1}tp://)[-a-zA-Z0-9@:%_+.~#?lt;a href="1"1/a', $text); $text = eregi_replace(' ([[:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn