Skip to content

Instantly share code, notes, and snippets.

@mamor
Last active December 12, 2015 09:39
Show Gist options
  • Save mamor/4753053 to your computer and use it in GitHub Desktop.
Save mamor/4753053 to your computer and use it in GitHub Desktop.
リンクを自動変換するメソッド 参考: http://d.hatena.ne.jp/kemworld/20080522/1211463240
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