함수 auto link text()

Jmnote (토론 | 기여)님의 2015년 4월 27일 (월) 10:23 판
auto_link_text()

1 PHP[1]

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/");

2 주석

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}