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

eregi_replace를 이용한 자동링크

페이지 정보

작성자 MintState 댓글 0건 조회 11,651회 작성일 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건 2 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
140 MintState 11530 10-31
139 MintState 11548 10-29
138 MintState 11550 10-31
열람중 MintState 11652 10-29
136 MintState 11668 02-23
135 MintState 11743 07-27
134 MintState 11750 10-29
133 MintState 11806 10-31
132 MintState 11886 11-03
131 MintState 11978 11-03
130 MintState 12079 10-28
129 MintState 12200 10-29
128 MintState 12269 10-29
127 MintState 12269 11-03
126 MintState 12278 11-12
125 MintState 12279 10-31
124 MintState 12289 11-03
123 MintState 12298 11-17
122 MintState 12301 10-29
121 MintState 12325 11-03
120 MintState 12437 02-23
119 MintState 12459 11-03
118 MintState 12480 11-10
117 MintState 12493 10-28
116 MintState 12531 11-03
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™