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

eregi_replace를 이용한 자동링크

페이지 정보

작성자 MintState 댓글 0건 조회 11,647회 작성일 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건 1 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
165 MintState 21137 10-28
164 MintState 13417 10-28
163 MintState 24120 10-28
162 MintState 13049 10-28
161 MintState 14502 10-28
160 MintState 23065 10-28
159 MintState 15911 10-28
158 MintState 12074 10-28
157 MintState 12489 10-28
156 MintState 11743 10-29
열람중 MintState 11648 10-29
154 MintState 12852 10-29
153 MintState 12194 10-29
152 MintState 10883 10-29
151 MintState 10986 10-29
150 MintState 9803 10-29
149 MintState 10587 10-29
148 MintState 12539 10-29
147 MintState 11546 10-29
146 MintState 11084 10-29
145 MintState 12266 10-29
144 MintState 14909 10-29
143 MintState 14811 10-29
142 MintState 14874 10-29
141 MintState 13439 10-29
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™