ASP - 텍스트 인코딩 ANSI to UTF-8


<%

Public Function URLEncodeUTF8(byVal szSource)



Dim szChar, WideChar, nLength, i, result
nLength = Len(szSource)



'szSource = Replace(szSource," ","+")



For i = 1 To nLength
 szChar = Mid(szSource, i, 1)



 If Asc(szChar) < 0 Then
  WideChar = CLng(AscB(MidB(szChar, 2, 1))) * 256 + AscB(MidB(szChar, 1, 1))



  If (WideChar And &HFF80) = 0 Then
   result = result & "%" & Hex(WideChar)
  ElseIf (WideChar And &HF000) = 0 Then
   result = result & _
   "%" & Hex(CInt((WideChar And &HFFC0) / 64) Or &HC0) & _
   "%" & Hex(WideChar And &H3F Or &H80)
  Else
   result = result & _
   "%" & Hex(CInt((WideChar And &HF000) / 4096) Or &HE0) & _
   "%" & Hex(CInt((WideChar And &HFFC0) / 64) And &H3F Or &H80) & _
   "%" & Hex(WideChar And &H3F Or &H80)
  End If
 Else
  result = result + szChar
 End If
Next
URLEncodeUTF8 = result
End Function




'---------------------------------------------------------------------
' URLDecodeUTF8 (UTF8 --> 아스키 )
' mongmong - 2003. 10 (URLEncodeUTF8 참조)
'---------------------------------------------------------------------




Public Function URLDecodeUTF8(byVal pURL)
Dim i, s1, s2, s3, u1, u2, result
pURL = Replace(pURL,"+"," ")



For i = 1 to Len(pURL)



 if Mid(pURL, i, 1) = "%" then



  s1 = CLng("&H" & Mid(pURL, i + 1, 2))



  '2바이트일 경우
  if ((s1 AND &HC0) = &HC0) AND ((s1 AND &HE0) <> &HE0) then
   s2 = CLng("&H" & Mid(pURL, i + 4, 2))



   u1 = (s1 AND &H1C) / &H04
   u2 = ((s1 AND &H03) * &H04 + ((s2 AND &H30) / &H10)) * &H10
   u2 = u2 + (s2 AND &H0F)
   result = result & ChrW((u1 * &H100) + u2)
   i = i + 5



  '3바이트일 경우
  elseif (s1 AND &HE0 = &HE0) then
   s2 = CLng("&H" & Mid(pURL, i + 4, 2))
   s3 = CLng("&H" & Mid(pURL, i + 7, 2))



   u1 = ((s1 AND &H0F) * &H10)
   u1 = u1 + ((s2 AND &H3C) / &H04)
   u2 = ((s2 AND &H03) * &H04 +  (s3 AND &H30) / &H10) * &H10
   u2 = u2 + (s3 AND &H0F)
   result = result & ChrW((u1 * &H100) + u2)
   i = i + 8
  end if
 else
  result = result & Mid(pURL, i, 1)
 end if
Next
URLDecodeUTF8 = result
End Function


    Dim stitle, sns_title, sns_url, sns_contents

    stitle = "테스트"

    response.write "ANSI : " & stitle & "<br>"

    sTitle = URLEncodeUTF8 (sTitle)
    sns_title  = replace(stitle, """", "'")

    response.write "UTF-8 : " & sns_title & "<br>"

    sns_url   = ""'"http://" & Request.ServerVariables("server_name") + "?idx="
    'sns_contents = replace(summary, """", "'") + "<br/>" + sns_url
%>

                                                <a target="_blank" href="http://twitter.com/home/?status=<%=sns_title%>:<%=sns_url%>"><img src="/images/content/news/icon_t.gif" alt="t" /></a>






크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 홍반장

2011/02/11 12:28 2011/02/11 12:28
, , ,
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/5865


사람들 간의 차이는 미미하다.
그러나 그 미미한 차이가 큰 차이를 만들어낸다.
미미한 차이는 태도이고,
큰 차이는 그 태도가 긍정적이냐 부정적이냐 하는 것이다.
(There is little difference in people,
but that little difference makes a big difference.
The little difference is attitude.
The big difference is whether it is positive or negative.)
-W. 클레멘트 스톤(W. Clement Stone)

세상에 절대적으로 좋거나 나쁜 것은 없습니다.
다만 우리의 생각이 그렇게 만들 뿐입니다.
인생의 전쟁은 강한 사람이나 빠른 사람에게 항상 승리를 안겨주지는 않습니다.
조만간 승리하는 사람은 자기가 할 수 있다고 믿는 사람입니다.
모든 일은 마음먹은 대로 이루어집니다.

In this world, there is no such thing as a completely good or bad thing.
It is only determined by how our mind decides to perceive it.
Victory does not always come to the strongest or quickest person.
Sooner or later, victory will be attained by those who believe
in themselves- everything depends on one’s determination and resolve.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 홍반장

2011/02/11 10:17 2011/02/11 10:17
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/5864

창조의 순간

순식간에 지나가는 생각, 특히나
구체적인 모든 심상을 포착하기란 쉽지 않다.
물론 일반적으로 사람들은 그렇게 할 생각조차
하지 않는다. 이것이 바로 직관 혹은 영감이라는
개념이 매우 흥미진진한 이유다. 사람들은
자신들의 의식적인 생각을 세세히
포착하려 하지 않는다. 설사
시도하더라도 잘 해내지 못한다.


- 마거린A. 보든의《창조의 순간》중에서 -


* 숲속 새소리를 듣는 것이 창조의 순간입니다.
생명력이 넘치는 아름다운 음악이 탄생되는 순간이니까요.
작은 들꽃, 우뚝한 나무 한 그루 바라보는 것이 예술입니다.
직관의 통로를 거쳐 멋들어진 그림이 될 수 있으니까요.
좋은 사람 하나 만나는 것이 창조의 순간입니다.
사랑이 시작되고, 꿈이 생겨나고,
기쁨이 퐁퐁 솟아나니까요.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 홍반장

2011/02/11 10:16 2011/02/11 10:16
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/5863


블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2011/02   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28          
Statistics Graph

Site Stats

Total hits:
187154
Today:
623
Yesterday:
789