Home>

Sometimes I have to transcode when encountering unicode,We had to manually encode and transcode.I saw a unitcode transcoding method on the Internet yesterday.very useful! Let's share it with you.

Javascript script unicode transcoding function:

<script type="text/javascript">
   var gb2312unicodeconverter={
    tounicode:function (str) {
      return escape (str) .tolocalelowercase (). replace (/%u/gi, "\\ u");
      }
    , togb2312:function (str) {
        return unescape (str.replace (/\\ u/gi, "%u"));
      }
  };
    var str="Shanghai", unicode;
  document.write (str + "<br />");
  unicode=gb2312unicodeconverter.tounicode (str);
  document.write ("Chinese character to unicode code:" + unicode + "<br /><br />");
  document.write ("Unicode code converted to Chinese characters:" + gb2312unicodeconverter.togb2312 (unicode));
</script>

This is a very well written transcoding tool.You can organize it into a common programming tool,Use it when needed!

  • Previous Usage and explanation of Closure class in PHP
  • Next Method for uploading excel and inserting excel into database by JSP