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

eregi_replace를 이용한 자동링크

페이지 정보

작성자 MintState 댓글 0건 조회 11,626회 작성일 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 12236 11-03
39 MintState 12233 10-29
38 MintState 12231 11-12
37 MintState 12172 10-29
36 MintState 12043 10-28
35 MintState 11952 11-03
34 MintState 11851 11-03
33 MintState 11776 10-31
32 MintState 11722 10-29
31 MintState 11701 07-27
30 MintState 11637 02-23
열람중 MintState 11627 10-29
28 MintState 11513 10-29
27 MintState 11505 10-31
26 MintState 11491 10-31
25 MintState 11411 11-10
24 MintState 11359 11-10
23 MintState 11296 11-03
22 MintState 11204 11-03
21 MintState 11122 10-31
20 MintState 11055 10-29
19 MintState 10956 10-29
18 MintState 10857 10-29
17 MintState 10770 10-31
16 MintState 10555 10-29
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™