網址字符串轉換成超級鏈接PHP代碼
來源:程序員人生 發布時間:2013-12-13 16:43:45 閱讀次數:3500次
該函數將 URL 和 E-mail 地址字符串轉換為可點擊的超級鏈接,代碼下:
- 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;
- }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈