Replace a list of emoticons with their images

Another approach: function replaceEmoticons(text) { var emoticons = { ‘:-)’ : ‘smile1.gif’, ‘:)’ : ‘smile2.gif’, ‘:D’ : ‘smile3.gif’ }, url = “http://www.domain.com/”; // a simple regex to match the characters used in the emoticons return text.replace(/[:\-)D]+/g, function (match) { return typeof emoticons[match] != ‘undefined’ ? ‘<img src=”‘+url+emoticons[match]+'”/>’ : match; }); } replaceEmoticons(‘this is a simple … Read more

Incorrect string value: ‘\xF0\x9F\x8E\xB6\xF0\x9F…’ MySQL

I was finally able to figure out the issue. I had to change some settings in mysql configuration my.ini This article helped a lot http://mathiasbynens.be/notes/mysql-utf8mb4#character-sets First i changed the character set in my.ini to utf8mb4 Next i ran the following commands in mysql client SET NAMES utf8mb4; ALTER DATABASE dreams_twitter CHARACTER SET = utf8mb4 COLLATE … Read more

Displaying emoticons in Android

I think it would be more useful to build Spannable. private static final Factory spannableFactory = Spannable.Factory .getInstance(); private static final Map<Pattern, Integer> emoticons = new HashMap<Pattern, Integer>(); static { addPattern(emoticons, “:)”, R.drawable.emo_im_happy); addPattern(emoticons, “:-)”, R.drawable.emo_im_happy); // … } private static void addPattern(Map<Pattern, Integer> map, String smile, int resource) { map.put(Pattern.compile(Pattern.quote(smile)), resource); } public static … Read more

tech