首页 > 语言 > PHP > 正文

网址字符串转换成超级链接PHP代码

2024-09-04 11:48:08
字体:大 中 小
来源:转载
供稿:网友

该函数将 URL 和 E-mail 地址字符串转换为可点击的超级链接,代码下:

  1. function makeClickableLinks($text)  
  2. {  
  3. $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);  
  4. return $text;  
  5. } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表