function auto_link_text($text) {
$pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
$callback = create_function('$matches',
'$url = array_shift($matches); return "<a href=\'$url\'>$url</a>";' );
return preg_replace_callback($pattern, $callback, $text);
}
echo auto_link_text("URL 링크달기 테스트 http://stackoverflow.com/questions/1188129/pregreplace-to-detect-html-php http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax 참고. 127.0.0.1 http://news.bbc.co.uk/1/hi/england/surrey/8168892.stm? 192.168.0.1:8080 https://example.net:1234/");