"함수 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...)
 
잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 5개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: 정규식]]
[[분류: 정규표현식]]
;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]]
<syntaxhighlight lang='PHP'>
<source lang='PHP'>
function auto_link_text($text) {
function auto_link_text($text) {
   $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
   $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
   $callback = create_function('$matches', '
   $callback = create_function('$matches',
$url = array_shift($matches);
      '$url = array_shift($matches); return "<a href=\'$url\'>$url</a>";' );
return "<a href=\'$url\'>$url</a>";
  ');
   return preg_replace_callback($pattern, $callback, $text);
   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/");
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/");
</source>
</syntaxhighlight>
 
==같이 보기==
*[[URL]]
*[[A 태그]]


==주석==
==주석==
<references/>
<references/>

2020년 11월 2일 (월) 02:36 기준 최신판

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 같이 보기[ | ]

3 주석[ | ]

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