Skip to content

Instantly share code, notes, and snippets.

@xurenlu
Created June 13, 2013 03:47
Show Gist options
  • Save xurenlu/5771126 to your computer and use it in GitHub Desktop.
Save xurenlu/5771126 to your computer and use it in GitHub Desktop.
nodejs-gbkUrlencode.js
function encodeURIComponentUTF8toGBK(utf8String){
var Iconv = require("iconv").Iconv;
var iconvLite=require("iconv-lite");
var Buffer =require("buffer").Buffer;
var iconv = new Iconv("UTF-8","GBK");
var res = iconv.convert(utf8String);
return encodeURIComponent(iconvLite.decode(res,"GBK"));
}
console.log(
encodeURIComponentUTF8toGBK("如何敷面膜")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment