Home > php教程 > php手册 > body text

用PHP将网址字符串转换成超链接(网址或email)

PHP中文网
Release: 2016-06-13 12:16:10
Original
1022 people have browsed it

用PHP将网址字符串转换成超链接(网址或email)

 代码如下:

function makeClickableLinks($text) { 
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '
\1
', $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; 
}
Copy after login


实现原理:
主要是利用正则原理,匹配网址字符或Email来替换成超级链接。

以上就是用PHP将网址字符串转换成超链接(网址或email)的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template