Where The Streets Have No Name

UTF-8 인코딩 본문

Developement/Web

UTF-8 인코딩

highheat 2007. 2. 19. 03:37
function toUTF8(szInput)
{
 var wch,x,uch="",szRet="";
 for (x=0; x<szInput.length; x++)
  {
  wch=szInput.charCodeAt(x);
  if (!(wch & 0xFF80)) {
   szRet += "%" + wch.toString(16);
  }
  else if (!(wch & 0xF000)) {
   uch = "%" + (wch>>6 | 0xC0).toString(16) +
      "%" + (wch & 0x3F | 0x80).toString(16);
   szRet += uch;
  }
  else {
   uch = "%" + (wch >> 12 | 0xE0).toString(16) +
      "%" + (((wch >> 6) & 0x3F) | 0x80).toString(16) +
      "%" + (wch & 0x3F | 0x80).toString(16);
   szRet += uch;
  }
 }
 return(szRet);