'링크주소 자동생성'에 해당되는 글 1건

  1. 2007/06/21 초록별사랑 본문에 웹사이트 주소가 있으면 자동으로 <a>태그를 생성해주는 함수.

'본문에 웹사이트 주소가 있으면 자동으로 <a>태그를 생성해주는 함수.
Function replaceLink(str)
   Dim patrn, regEx, match, matches, RetStr, regEx2, strEx

   patrn = "http:\/\/[0-9a-zA-Z./~_-]+( ?|$)"
   SET regEx = New RegExp           ' 정규식을 만듭니다.
   regEx.Pattern = patrn            ' 패턴을 설정합니다.
   regEx.IgnoreCase = True            ' 대/소문자를 구분하지 않도록 합니다.
   regEx.Global = True         ' 전체 문자열을 검색하도록 설정합니다.
   SET Matches = regEx.Execute(str)

   SET regEx2 = New RegExp            ' 정규식을 만듭니다.
   regEx2.IgnoreCase = True            ' 대/소문자를 구분하지 않도록 합니다.
   regEx2.Global = True         ' 전체 문자열을 검색하도록 설정합니다.

   For Each Match in Matches      ' Matches 컬렉션을 반복합니다.   
       regEx2.Pattern = Match.Value            ' 패턴을 설정합니다.
       strEx = Match.Value
       str = regEx2.Replace(str, "<a href='" & strEx & "' target='_blank'>" & strEx & "</a>")
   Next

   replaceLink = str
End Function

크리에이티브 커먼즈 라이센스
Creative Commons License
2007/06/21 11:16 2007/06/21 11:16
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://haroc.haroc.net/tc/rss/response/68