PHPackages                             chefkoch/morphoji - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chefkoch/morphoji

ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

chefkoch/morphoji
=================

A library to convert UTF-8 emoji characters to latin1 placeholders and vice versa.

1.1.0(9y ago)14136.9k↓16.5%3[1 issues](https://github.com/chefkoch-dev/morphoji/issues)[3 PRs](https://github.com/chefkoch-dev/morphoji/pulls)1MITPHPPHP &gt;=5.5.0

Since Dec 13Pushed 1y ago12 watchersCompare

[ Source](https://github.com/chefkoch-dev/morphoji)[ Packagist](https://packagist.org/packages/chefkoch/morphoji)[ Docs](https://github.com/chefkoch-dev/morphoji)[ RSS](/packages/chefkoch-morphoji/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (7)Used By (1)

Morphoji
========

[](#morphoji)

[![Build Status](https://camo.githubusercontent.com/567866aa559e2a8e03daf443fa070af26266fcd57b2f4f5ecad65d77b8d94383/68747470733a2f2f7472617669732d63692e6f72672f636865666b6f63682d6465762f6d6f7270686f6a692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chefkoch-dev/morphoji)

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

Use Case
--------

[](#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](https://en.wikipedia.org/wiki/UTF-8#Description). Unfortunately the bulk of the [Emoji characters](https://unicode-table.com/en/#emoticons) 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

[](#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](https://mathiasbynens.be/notes/mysql-utf8mb4).

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](https://unicode-table.com/en/#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
-----

[](#usage)

Morphoji can be required via [Composer](https://getcomposer.org) in the project where you want to use it:

```
composer require chefkoch/morphoji
```

### Converting

[](#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

[](#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, '&nbsp;');

// results in $wrapped == 'Lorem &nbsp; ipsum'
```

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

How it works
------------

[](#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](http://www.unicode.org/Public/emoji/5.0/).

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?

[](#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
---------------

[](#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
-----

[](#tests)

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

To run them:

```
composer install
vendor/bin/phpunit
```

License
-------

[](#license)

Morphoji is licensed under the [MIT License](LICENSE).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance25

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Total

5

Last Release

3344d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7f75d8c2740751a37b68fddf3e5115630cc920ad038c1783b291a3460842d652?d=identicon)[nem75](/maintainers/nem75)

---

Top Contributors

[![nem75](https://avatars.githubusercontent.com/u/1327785?v=4)](https://github.com/nem75 "nem75 (20 commits)")[![frastel](https://avatars.githubusercontent.com/u/433380?v=4)](https://github.com/frastel "frastel (4 commits)")

---

Tags

emojiutf8unicodeemoji

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chefkoch-morphoji/health.svg)

```
[![Health](https://phpackages.com/badges/chefkoch-morphoji/health.svg)](https://phpackages.com/packages/chefkoch-morphoji)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[voku/portable-utf8

Portable UTF-8 library - performance optimized (unicode) string functions for php.

52322.4M40](/packages/voku-portable-utf8)[rinvex/countries

Rinvex Countries is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.

1.7k7.4M48](/packages/rinvex-countries)[joypixels/emoji-toolkit

JoyPixels is a complete set of emoji designed for the web. The emoji-toolkit includes libraries to easily convert unicode characters to shortnames (:smile:) and shortnames to JoyPixels emoji images. PNG formats provided for the emoji images.

465817.1k7](/packages/joypixels-emoji-toolkit)[jbroadway/urlify

A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

6737.4M62](/packages/jbroadway-urlify)[ausi/slug-generator

Slug Generator

8002.2M22](/packages/ausi-slug-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
