Last active
October 3, 2015 02:37
-
-
Save asika32764/2374110 to your computer and use it in GitHub Desktop.
字串中網址自動加上超連結
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* 字串中網址自動加上超連結 | |
* via http://blog.kidwm.net/68 | |
*/ | |
function addLink($str) { | |
$str = preg_replace('#(http|https|ftp|telnet)://([0-9a-z\.\-]+)(:?[0-9]*)([0-9a-z\_\/\?\&\=\%\.\;\#\-\~\+]*)#i','<a | |
href="\1://\2\3\4" rel="nofollow">\1://\2\3\4</a>', $str); | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment