All Projects → chefkoch-dev → morphoji

chefkoch-dev / morphoji

Licence: MIT license
PHP emoji converter

Programming Languages

PHP
23972 projects - #3 most used programming language

Labels

Projects that are alternatives of or similar to morphoji

gomoji
Helpful functions to work with emoji in Golang
Stars: ✭ 63 (+384.62%)
Mutual labels:  emoji
EmojiReader
A simple tool to recognize Emoji in string. (JavaScript & Java)
Stars: ✭ 61 (+369.23%)
Mutual labels:  emoji
kekfinder
Emoji finding tool
Stars: ✭ 17 (+30.77%)
Mutual labels:  emoji
whatsapp-bot
Made with Python and Selenium, can be used to send multiple messages and send messages as characters made of emojis
Stars: ✭ 34 (+161.54%)
Mutual labels:  emoji
emojis
An emoji management bot for Discord.
Stars: ✭ 18 (+38.46%)
Mutual labels:  emoji
vuejs-emoji
vue2.x emoji plugin, autoload fontawesome
Stars: ✭ 32 (+146.15%)
Mutual labels:  emoji
recyclebin
♻️ measures usage of a particular term on twitter
Stars: ✭ 21 (+61.54%)
Mutual labels:  emoji
github emoji
all emojis in github
Stars: ✭ 77 (+492.31%)
Mutual labels:  emoji
noto-color-emoji-font
Color emoji SVGinOT font using Noto emoji, with multiple releases, such as Lollipop and Nougat. Linux/MacOS/Windows
Stars: ✭ 32 (+146.15%)
Mutual labels:  emoji
GithubEmoji
Github emoji in markdown documents and commit messages for Sublime Text
Stars: ✭ 30 (+130.77%)
Mutual labels:  emoji
domino
a tool for collaging thoughts
Stars: ✭ 83 (+538.46%)
Mutual labels:  emoji
animated-emoji-gen
The tool makes it easy to create animated GIFs of Slack custom emoji.
Stars: ✭ 53 (+307.69%)
Mutual labels:  emoji
DreamBig
☁🌝☁ 3D emoji drawing iPad app with ARKit and the Apple Pencil ☁🌝☁
Stars: ✭ 24 (+84.62%)
Mutual labels:  emoji
favioli
Emoji Favicons for the web. 👊🤯
Stars: ✭ 55 (+323.08%)
Mutual labels:  emoji
erk
Ərk is an open source, cross-platform IRC client written in Python 3, Qt 5, and Twisted.
Stars: ✭ 21 (+61.54%)
Mutual labels:  emoji
EmojiKeyBoard
自定义表情键盘(支持系统表情, 图片表情),仅供参考学习~
Stars: ✭ 36 (+176.92%)
Mutual labels:  emoji
three-wise-monkeys
You've heard of the SKI combinators... How about the 🙊🙉🙊 combinators?
Stars: ✭ 27 (+107.69%)
Mutual labels:  emoji
WeChat
Wechat: 一款使用javafx实现的网络聊天室。
Stars: ✭ 29 (+123.08%)
Mutual labels:  emoji
emojibot
Emojibot is a Slack bot that announces new custom emoji to a specific channel.
Stars: ✭ 17 (+30.77%)
Mutual labels:  emoji
unicodemoticon
Trayicon with Unicode Emoticons using Python3 Qt5
Stars: ✭ 21 (+61.54%)
Mutual labels:  emoji

Morphoji

Build Status

Morphoji is a tiny PHP library to morph Unicode Emoji characters 🤗 into Latin1 placeholders🙀 and back. 👍

Use Case

Why would you want to do this in the first place? Maybe for the same reason I did: you got a big old MySQL Database with all text columns defined as utf8. Great, because with utf8 you can store everything Unicode has to offer, including Emoji characters, right?

Wrong-o.

Apparently utf8 in MySQL (and some other applications) is limited to 3 Byte Unicode characters. Unfortunately the bulk of the Emoji characters is found in 4 Byte Unicode space.

Trying to store those Emoji (and other 4 Byte characters) in a MySQL utf8 table will result in those characters silently getting lost.

utf8mb4

Of course there is a systematic solution for this. Convert the columns in question (and your database connections to them) from utf8 to utf8mb4. THAT charset is actually able to store ALL of the characters specified by Unicode.

If you want to go that route (which is by far the cleanest approach) Mathias Bynens wrote a great article on that.

But also, if your database is really big and has lots of text columns and you don't want to convert just a few columns to the new charset but all of them (because consistency and because you will have to change your connection's charset as well) and you really only care about Emoji and not about characters for Ancient Greek Musical Notation aaand you just did all that converting a couple of years ago for utf8 and don't really have the time and nerve to do it again ...

... you could just use Morphoji.

Usage

Morphoji can be required via Composer in the project where you want to use it:

composer require chefkoch/morphoji

Converting

Now if you have $text containing (possibly) Emoji characters handle it like this:

$text = '...'; // Some text with unicode emojis.


$converter = new \Chefkoch\Morphoji\Converter();

// From utf-8 text to db.
$textForDb = $converter->fromEmojis($text);
$db->insert($textForDb); // Dummy code for DB insert command.

// From db to utf-8 text.
$textWithEmoji = $converter->toEmojis($db->getTextWithPlaceholders());
return new Response($textWithEmoji); // Dummy code for HTML response to browser.

Wrapping

Additionally you can convert a string with emoji placeholders to a string where these placeholders are wrapped with arbitray prefix and suffix.

For example you can use this to decorate the placeholders with tags.

$placeholderText = 'Lorem :emoji-12345: ipsum';

$converter = new \Chefkoch\Morphoji\Converter();

$wrapped = $converter->wrap($placeholderText, ' ');

// results in $wrapped == 'Lorem <span class="emoji" data-emoji-code="12345">&nbsp;</span> ipsum'

This way you can replace them with your own graphics when rendering the text in whatever your frontend may be.

How it works

Morphoji will only convert characters which have an official emoji representation. This happens by using a regular expression derived from official Unicode charts.

Every character matching that regular expression will be converted into a latin1 placeholder:

:emoji-[hex code]:

E.g. a replaced "face blowing a kiss" Emoji (1F618, 😘) will be represented as :emoji-1f618:.

Converting the placeholder back works with an according regex; other than that it's pretty much vice versa.

Why not just convert into HTML entities and then use those in the output?

Morphoji aims to be output device agnostic. If you just want to HTML everything that's fine, but in that case this is probably not the library you are looking for.

In my case the data stored in the database isn't necessarily output in an HTML context, so being able to convert the entities back is mandatory. (And in a time where almost all output devices / applications are able to handle full UTF-8 it is the generally cleaner approach.)

Other languages

There are no plans to implement this in any other language. Coming up with the emoji detection regex is about half the work, if you want to use it in your own implementation: go ahead.

Tests

If you want to contribute, please don't forget to add / adapt the tests.

To run them:

composer install
vendor/bin/phpunit

License

Morphoji is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].