"함수 auto link text()"의 두 판 사이의 차이

(새 문서: 분류: 정규식 ;auto_link_text() ==PHP<ref>http://stackoverflow.com/questions/1959062/how-to-add-anchor-tag-to-a-url-from-text-input</ref> == categoet: PHP <source lang='P...)
 
2번째 줄: 2번째 줄:
;auto_link_text()
;auto_link_text()


==PHP<ref>http://stackoverflow.com/questions/1959062/how-to-add-anchor-tag-to-a-url-from-text-input</ref>
==PHP<ref>http://stackoverflow.com/questions/1959062/how-to-add-anchor-tag-to-a-url-from-text-input</ref>==
==
[[분류: PHP]]
[[categoet: PHP]]
<source lang='PHP'>
<source lang='PHP'>
function auto_link_text($text) {
function auto_link_text($text) {

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 }}