Download the PHP package steppinghat/emoji-detector without Composer
On this page you can find all versions of the php package steppinghat/emoji-detector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download steppinghat/emoji-detector
More information about steppinghat/emoji-detector
Files in steppinghat/emoji-detector
Package emoji-detector
Short Description Detect and validate emoji in an input string
License MIT
Homepage https://github.com/steppinghat/emoji-detector
Informations about the package emoji-detector
PHP Emoji Detector
Have an input string full of emoji's and you want to know detailed information about each emoji? Want to build an easy way to validate emoji's that come in as input data?
This :clap: is :clap: the :clap: library :clap: you :clap: want!
What does this thing do?
This library simply parses input strings and returns a list of relevant information about emoji's that are present in the string. It currently supports version 15.1 of the emoji standard.
Installation
Install this library using composer
ℹ️ We recommend using the Caret Version Range (^
) (see below for why)
Updates
Updates to the Unicode version will always be released as new minor versions. We recommend using the (^
)
caret version range so that new Emoji's are automatically supported in your project when running composer update
.
Any breaking changes will be released as new major versions, and bugfixes will be released as new patch versions as usual.
Usage
- The Model
- Emoji detection
- Detect distinct emojis
- Testing for single emojis
- Testing if a string is completely emojis
The Model
For most outputs, the library will provide an EmojiInfo
object that contains all of the relevant information about an emoji.
The object will contain the following information:
Property | Description |
---|---|
emoji |
The emoji chacater itself |
name |
A user friendly name of the specific emoji |
shortName |
A shortened name of the emoji |
category |
A user friendly category name for the emoji |
skinTone |
The level of skin tone of the emoji (if present) |
hexCodes |
An array of individual hexadecimal characters that are used to make up the emoji |
offset |
The position in the string where the emoji starts |
mbOffset |
The multibyte position in the string where the emoji starts |
All of these properties are protected, but can be accessed by their appropriate getters and setters. E.g. getCategory()
or getSkinTone()
.
Emoji detection
This example is the most common usage of the detector, returning an array of objects that provide detailed information about each emoji found in the input string.
The library has full support for complex emoji's that make use of the ZWJ (Zero Width Joiner) character.
The above will produce the following output:
Detect distinct emojis
If you only want to detect distinct emojis in a string, you can use the detectDistinct
method. This will return an array of distinct emojis found in the input string, and the position of the first distinct occurence of that emoji.
The above will produce the following output:
Testing for single emojis
Sometimes it is handy to test if an input string is a single emoji on it's own.
Testing if a string is completely emojis
Similar to calling, isSingleEmoji
, calling isEmojiString
will check if a string only contains emojis.
Tests
Included for library development purposes is a small set of test cases to assure that basic library functions work as expected. These tests can be launched by running the following:
License
Made with :heart: by Javan Eskander
Available for use under the MIT license.
Emoji data sourced from amio/emoji.json
All versions of emoji-detector with dependencies
ext-mbstring Version *
ext-json Version *