YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > PHP
검색
멤버이름    오토
비밀번호 
 

eregi_replace를 이용한 자동링크

페이지 정보

작성자 MintState 댓글 0건 조회 11,650회 작성일 08-10-29 17:08

본문

eregi_replace를 이용한 자동링크

방법 1)
$content = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "\1://\2\3", $content); 
$content = eregi_replace("([_a-z0-9.]+)@([_a-zA-Z0-9.]+)", "\1@\2", $content);  


방법 2)
function url_auto_link( $text, $target="_blank" ) 
{ 
    // 문자열에 url이 있을 경우 자동으로 링크를 걸어준다. 
    $url_patten = "((http|https|ftp|telnet|news)://[a-z0-9-]+.[][a-zA-Z0-9:&#@=_~%;?/.+-]+)"; 
    $text       = eregi_replace( $url_patten, "<a href='\1' target='$target'>\1</a>", $text ); 

    return $text; 
} 


방법 3)
function auto_link($str)  
{ 
    $str=explode("\n",$str); 
    $str=implode("\n ",$str); 

    $str=" ".$str; 
    $str = eregi_replace( ">http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)", "><a href=http://\\1 target=_blank>http://\\1</a>", $str); 
    $str = eregi_replace( "\(http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)\)", "(<a href=http://\\1 target=_blank>http://\\1</a>)", $str); 
    $str = eregi_replace( "&nbsp;&nbsp;http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)", "&nbsp;&nbsp;<a href=http://\\1 target=_blank>http://\\1</a>", $str); 
    $str = eregi_replace( " http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)", " <a href=http://\\1 target=_blank>http://\\1</a>", $str); 

    $str = eregi_replace(" ([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+){1,})", " <a href=mailto:\\1>\\1</a>", $str); 

    return $str; 
}

댓글목록

등록된 댓글이 없습니다.

Total 165건 6 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
40 MintState 12277 11-12
39 MintState 12268 10-29
38 MintState 12268 11-03
37 MintState 12199 10-29
36 MintState 12079 10-28
35 MintState 11977 11-03
34 MintState 11886 11-03
33 MintState 11805 10-31
32 MintState 11748 10-29
31 MintState 11741 07-27
30 MintState 11667 02-23
열람중 MintState 11651 10-29
28 MintState 11550 10-31
27 MintState 11548 10-29
26 MintState 11529 10-31
25 MintState 11449 11-10
24 MintState 11390 11-10
23 MintState 11322 11-03
22 MintState 11237 11-03
21 MintState 11157 10-31
20 MintState 11089 10-29
19 MintState 10990 10-29
18 MintState 10888 10-29
17 MintState 10798 10-31
16 MintState 10590 10-29
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™