function encode(str) { var s = ''; for (var i = 0; i < str.length; i++) { s += '&#' + str.charCodeAt(i) + ';'; } return s; }