// 입력내용중 URL부분을 자동링크로 반환하기;
function autolink($contents) {
$pattern = "/(http|https|ftp|mms):\/\/[0-9a-z-]+(\.[_0-9a-z-]+)+(:[0-9]{2,4})?\/?"; // domain+port
$pattern .= "([\.~_0-9a-z-]+\/?)*"; // sub roots
$pattern .= "(\S+\.[_0-9a-z]+)?"; // file & extension string
$pattern .= "(\?[_0-9a-z#%&=\-\+]+)*/i"; // parameters
$replacement = "\\0";
return preg_replace($pattern, $replacement, $contents, -1);
}
$autolinked = autolink($contents);
$autolinked = str_replace("\n", "
\r\n", $autolinked);
echo $autolinked;
?>