Last active
December 12, 2015 09:39
-
-
Save mamor/4753053 to your computer and use it in GitHub Desktop.
リンクを自動変換するメソッド
参考: http://d.hatena.ne.jp/kemworld/20080522/1211463240
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
public static function auto_link($str, $is_blank = true) | |
{ | |
$target = $is_blank ? ' target="_blank"' : ''; | |
$patterns = array("/(https?|ftp)(:\/\/[[:alnum:]\+\$\;\?\.%,!#~*\/:@&=_-]+)/i"); | |
$replacements = array("<a href=\"\\1\\2\"{$target}>\\1\\2</a>"); | |
return preg_replace($patterns, $replacements, $str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment