Defined:
Emoji is the international expression
Scene:
Emoji expression input and display on 1,IOS,ANDROID,WP
2,web also need to be as a support platform for emoji expression on line input and display (parsing)
Problem:
1,app input expression on the Web side of the display is garbled (such as square brackets, question marks, and the actual encoding)
2,mysql Storage Emoji Report Exception (0xF0 0x9F 0x8F 0x8), this record does not do problem handling, please refer to the http://blog.csdn.net/qdkfriend/article/details/7576524
Workaround: Handle the Web display (issue 1) for the moment
Required JS Library, in order to rely on
Emoji-list-with-image.js stores emoji encoded and emoji image data in formats such as ["e415", "1f604", "Ivborw0kgg ..."]
Punycode.js Encoding Parsing Library
Emoji.js parsing emoji encoding
Example usage
// parse the stored emoji expression function Parse (ARG) { if (typeof Ionull! = ' undefined ') {return IoNull.emoji.parse (ARG); } return ';};
//Inverse parsing (on the web, picture data is converted to emoji character-encoded storage)functionDecode (htmlstr) {//TODO regular replacement performance better? unicode16= "1f603" if(typeofIonull = = ' undefined ') { return‘‘; } varTempStr = htmlstr, unis = ", $imgs = $ (' <div> '). Append (Htmlstr). FIND (' img '); $.each ($imgs,function(i, O) {var$img =$ (O); varUnicode16 = ' 0x ' + $img. attr (' Unicode16 ');//hexadecimalUnicode16 =IoNull.emoji.decodeChar (UNICODE16); //Unis + = Unicode16;TempStr = Tempstr.replace ($ (' <div> ')). Append ($img). HTML (), UNICODE16); }); //System.log (UNIS) returntempstr;};
Emoji.js provides a getemojilist method that gets a collection of emoji arrays for all categories, where the single-item format is [0: "e415", 1: "1f604", 2:"Emoji corresponding base64 picture data"]
//sample generate emoji picture inputfunctionRenderemoji () {varEmos = getemojilist () [0];//whether to generate all emoji on demand here varhtml = ' <div > Common Expressions </div><ul> '; for(varj = 0; J < Emos.length; J + +) { varEmo =Emos[j]; vardata = ' data:image/png;base64, ' + emo[2]; if(j% 20 = = 0) {HTML+ = ' <li class= ' > '; } Else{html+ = ' <li> '; } HTML+ = ' </li> ;‘; }//.......}
At this point, the main emoji parsing and anti-parsing have been processed
Attached JS Library compression package Download Http://files.cnblogs.com/jtans/emoji-lib.zip
A record of input and display on the web based on emoji international expressions