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

eregi_replace를 이용한 자동링크

페이지 정보

작성자 MintState 댓글 0건 조회 11,569회 작성일 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 12473 10-31
39 MintState 13224 10-31
38 MintState 11431 10-31
37 MintState 12916 10-31
36 MintState 13638 10-31
35 MintState 11433 10-31
34 MintState 11067 10-31
33 MintState 17853 10-31
32 MintState 14496 10-31
31 MintState 11721 10-31
30 MintState 13527 10-29
29 MintState 17830 10-29
28 MintState 12207 10-29
27 MintState 10418 10-29
26 MintState 16333 10-29
25 MintState 13339 10-29
24 MintState 14734 10-29
23 MintState 14722 10-29
22 MintState 14817 10-29
21 MintState 12182 10-29
20 MintState 11007 10-29
19 MintState 11461 10-29
18 MintState 12442 10-29
17 MintState 10504 10-29
16 MintState 9727 10-29
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™