PHPackages                             andrewdavid/emoji-detector - 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. andrewdavid/emoji-detector

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

andrewdavid/emoji-detector
==========================

Detect and return all emoji found in a string

1.0.0(2y ago)011MITPHPPHP &gt;=7.2

Since May 26Pushed 2y agoCompare

[ Source](https://github.com/AndrewDavid/emoji-detector-php)[ Packagist](https://packagist.org/packages/andrewdavid/emoji-detector)[ Docs](https://github.com/AndrewDavid/emoji-detector-php)[ RSS](/packages/andrewdavid-emoji-detector/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Emoji Detection
===============

[](#emoji-detection)

This library will find all emoji in an input string and return information about each emoji character. It supports emoji with skin tone modifiers, as well as the composite emoji that are made up of multiple people.

Installation
------------

[](#installation)

```
composer require andrewdavid/emoji-detector

```

Or include `src/emoji-detector/Emoji.php` in your project, and make sure the `map.json` and `regexp.json` files are available in the same folder as `Emoji.php`. You don't need any of the other files for use in your own projects.

Usage
-----

[](#usage)

### Detect Emoji

[](#detect-emoji)

```
$input = "Hello 👍🏼 World 👨‍👩‍👦‍👦";
$emoji = (new Emoji\EmojiDetector())->detectEmoji($input);

print_r($emoji);
```

The function returns an array with details about each emoji found in the string.

```
Array
(
    [0] => Array
        (
            [emoji] => 👍🏼
            [short_name] => +1
            [num_points] => 2
            [points_hex] => Array
                (
                    [0] => 1F44D
                    [1] => 1F3FC
                )
            [hex_str] => 1F44D-1F3FC
            [skin_tone] => skin-tone-3
            [byte_offset] => 6
            [grapheme_offset] => 6
        )
    [1] => Array
        (
            [emoji] => 👨‍👩‍👦‍👦
            [short_name] => man-woman-boy-boy
            [num_points] => 7
            [points_hex] => Array
                (
                    [0] => 1F468
                    [1] => 200D
                    [2] => 1F469
                    [3] => 200D
                    [4] => 1F466
                    [5] => 200D
                    [6] => 1F466
                )
            [hex_str] => 1F468-200D-1F469-200D-1F466-200D-1F466
            [skin_tone] =>
            [byte_offset] => 21
            [grapheme_offset] => 14
        )
)

```

- `emoji` - The emoji sequence found, as the original byte sequence. You can output this to show the original emoji.
- `short_name` - The short name of the emoji, as defined by [Slack's emoji data](https://github.com/iamcal/emoji-data).
- `num_points` - The number of unicode code points that this emoji is composed of.
- `points_hex` - An array of each unicode code point that makes up this emoji. These are returned as hex strings. This will also include "invisible" characters such as the ZWJ character and skin tone modifiers.
- `hex_str` - A list of all unicode code points in their hex form separated by hyphens. This string is present in the [Slack emoji data](https://github.com/iamcal/emoji-data) array.
- `skin_tone` - If a skin tone modifier was used in the emoji, this field indicates which skin tone, since the `short_name` will not include the skin tone.
- `byte_offset` - The position of the emoji in the string in bytes, used with the plain `str*` functions
- `grapheme_offset` - The position of the emoji in the string, counting each emoji as 1 char, used with the `grapheme_*` functions

You can use the `grapheme_*` functions to extract parts of the string using the `grapheme_offset` position returned. For example:

```
$string = "Trešnja 🍒";
$emoji = (new Emoji\EmojiDetector())->detectEmoji($string);
echo '.'.grapheme_substr($string, 0, $emoji[0]['grapheme_offset']).".\n";
echo '.'.substr($string, 0, $emoji[0]['byte_offset']).".\n";
// Both output ".Trešnja ."
```

#### Replace emoji with string representations

[](#replace-emoji-with-string-representations)

```
$string = (new Emoji\EmojiDetector())->replaceEmoji('I like 🌮 and 🌯', ':', ':');
echo $string;
// I like :taco: and :burrito:
```

### Test if a string is a single emoji

[](#test-if-a-string-is-a-single-emoji)

Since simply counting the number of unicode characters in a string does not tell you how many visible emoji are in the string, determining whether a single character is an emoji is more involved. This function will return the emoji data only if the string contains a single emoji character, and false otherwise.

```
$emoji = (new Emoji\EmojiDetector())->isSingleEmoji('👨‍👩‍👦‍👦');
print_r($emoji);
```

```
Array
(
    [emoji] => 👨‍👩‍👦‍👦
    [short_name] => man-woman-boy-boy
    [num_points] => 7
    [points_hex] => Array
        (
            [0] => 1F468
            [1] => 200D
            [2] => 1F469
            [3] => 200D
            [4] => 1F466
            [5] => 200D
            [6] => 1F466
        )

    [hex_str] => 1F468-200D-1F469-200D-1F466-200D-1F466
    [skin_tone] =>
    [byte_offset] => 0
    [grapheme_offset] => 0
)

```

```
$emoji = (new Emoji\EmojiDetector())->isSingleEmoji('😻🐈');
// false
```

License
-------

[](#license)

Copyright 2017-2022 by Aaron Parecki.

Available under the MIT license.

Emoji data sourced from [iamcal/emoji-data](https://github.com/iamcal/emoji-data) under the MIT license.

Emoji parsing regex sourced from [EmojiOne](https://github.com/Ranks/emojione) under the MIT license.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 68.5% 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

Unknown

Total

1

Last Release

1080d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/260ba55471990638760015c0f2615d6839e44f196aada2bbb02e8ca59bb251f8?d=identicon)[AndrewDavidJ](/maintainers/AndrewDavidJ)

---

Top Contributors

[![aaronpk](https://avatars.githubusercontent.com/u/113001?v=4)](https://github.com/aaronpk "aaronpk (50 commits)")[![dmongeau](https://avatars.githubusercontent.com/u/124966?v=4)](https://github.com/dmongeau "dmongeau (8 commits)")[![AndrewDavid](https://avatars.githubusercontent.com/u/203713?v=4)](https://github.com/AndrewDavid "AndrewDavid (6 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (3 commits)")[![sebsel](https://avatars.githubusercontent.com/u/16517999?v=4)](https://github.com/sebsel "sebsel (3 commits)")[![twofed1](https://avatars.githubusercontent.com/u/35243523?v=4)](https://github.com/twofed1 "twofed1 (2 commits)")[![Zegnat](https://avatars.githubusercontent.com/u/490579?v=4)](https://github.com/Zegnat "Zegnat (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andrewdavid-emoji-detector/health.svg)

```
[![Health](https://phpackages.com/badges/andrewdavid-emoji-detector/health.svg)](https://phpackages.com/packages/andrewdavid-emoji-detector)
```

###  Alternatives

[daijie/aria2

talk with aria2

726.8k](/packages/daijie-aria2)

PHPackages © 2026

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