A record of input and display on the web based on emoji international expressions

Source: Internet
Author: User
Tags base64

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&gt ;‘; }//.......}

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.