emoji-picker icon indicating copy to clipboard operation
emoji-picker copied to clipboard

How to show emoji on p / span tag

Open fammifarendra opened this issue 6 years ago • 2 comments

We create emoji then save it to db, after that how to show the emoji that we saved into p or span tag ?

fammifarendra avatar Feb 15 '19 07:02 fammifarendra

there's no further explanation on this, so i try myself and create js function

function showsmiley( input) { var k, len, split_on_unicode, text, val; if (!input) { return ''; } if (!Config.rx_codes) { Config.init_unified(); } split_on_unicode = input.split(Config.rx_codes); for (k = 0, len = split_on_unicode.length; k < len; k++) { text = split_on_unicode[k]; val = ''; if (Config.rx_codes.test(text)) { val = Config.reversemap[text]; if (val) { val = ':' + val + ':'; val = $.emojiarea.createIcon($.emojiarea.icons[val]); } } else { // val = document.createTextNode(text); } // element.append(val); } return input.replace(Config.rx_codes, function(m) { var $img; val = Config.reversemap[m]; if (val) { val = ':' + val + ':'; $img = $.emojiarea.createIcon($.emojiarea.icons[val]); return $img; } else { return ''; } }); };

and this is how to call it showsmiley(yourunicodeinput);

fammifarendra avatar Feb 15 '19 07:02 fammifarendra

Your database probably needs to be configured to accept 4 byte utf-8 characters. Here's the documentation for mysql.

patrick-mcdougle avatar Apr 09 '19 21:04 patrick-mcdougle