PHP将字符串网址转换成链接,该函数将 URL 和 E-mail 地址字符串转换为可点击的超级链接。
<pre class="brush:php;"> function makeClickableLinks($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'<a href="\\1">\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'\1<a href="http://\\2">\2</a>', $text);
$text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',
'<a href="mailto:\\1">\1</a>', $text);
return $text;
}
```
PHP 字符串 网址 转换 链接