Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aleksey-anisimov/emoji
Library allows to detect emoji, remove emoji, encode emoji and decode emoji in string.
https://github.com/aleksey-anisimov/emoji
emoji emoji-unicode emojis
Last synced: about 2 months ago
JSON representation
Library allows to detect emoji, remove emoji, encode emoji and decode emoji in string.
- Host: GitHub
- URL: https://github.com/aleksey-anisimov/emoji
- Owner: aleksey-anisimov
- License: mit
- Created: 2021-10-20T08:44:53.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-14T10:34:12.000Z (over 2 years ago)
- Last Synced: 2024-10-13T18:09:38.767Z (3 months ago)
- Topics: emoji, emoji-unicode, emojis
- Language: PHP
- Homepage:
- Size: 45.9 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-php-cn - aleksey-anisimov/Emoji - 一个库来检测表情符号,删除表情符号,编码表情符号和解码字符串的表情符号. (目录 / 字符串 Strings)
README
### It allows to detect emoji, remove emoji, encode emoji and decode emoji in string.
# Installation
```
composer require anisimov/emoji
```# How to use
## Encode and decode Emoji
### Single colon delimiter
```php
$delimiter = new \Anisimov\Emoji\Delimiter\SingleColonDelimiter();
$emoji = new \Anisimov\Emoji\Emoji($delimiter);$stringWithEmoji = 'some string 😉';
$result = $emoji->encode($stringWithEmoji); // some string :wink:
$stringWithEncodedEmoji = 'some string :wink:';
$result = $emoji->decode($stringWithEmoji); // some string 😉
```### Double colon delimiter
```php
$delimiter = new \Anisimov\Emoji\Delimiter\DoubleColonDelimiter();
$emoji = new \Anisimov\Emoji\Emoji($delimiter);$stringWithEmoji = 'some string 😉';
$result = $emoji->encode($stringWithEmoji); // some string ::wink::
$stringWithEncodedEmoji = 'some string ::wink::';
$result = $emoji->decode($stringWithEmoji); // some string 😉
```### Triple colon delimiter
```php
$delimiter = new \Anisimov\Emoji\Delimiter\TripleColonDelimiter();
$emoji = new \Anisimov\Emoji\Emoji($delimiter);$stringWithEmoji = 'some string 😉';
$result = $emoji->encode($stringWithEmoji); // some string :::wink:::
$stringWithEncodedEmoji = 'some string :::wink:::';
$result = $emoji->decode($stringWithEmoji); // some string 😉
```## Detect emoji in string
```php
$delimiter = new \Anisimov\Emoji\Delimiter\SingleColonDelimiter();
$emoji = new \Anisimov\Emoji\Emoji($delimiter);$stringWithEmoji = 'some string 😉';
$result = $emoji->hasEmoji($stringWithEmoji); // true
$stringWithoutEmoji = 'some string';
$result = $emoji->hasEmoji($stringWithoutEmoji); // false
```---
## Remove all emoji in string
```php
$delimiter = new \Anisimov\Emoji\Delimiter\SingleColonDelimiter();
$emoji = new \Anisimov\Emoji\Emoji($delimiter);$stringWithEmoji = '😉 some 😉 😉 😉 string 😉';
$result = $emoji->remove($stringWithEmoji); // 'some string'
```---
## Find all emoji in string
```php
$delimiter = new \Anisimov\Emoji\Delimiter\SingleColonDelimiter();
$emoji = new \Anisimov\Emoji\Emoji($delimiter);$stringWithEmoji = '😀 some 😃 😄 string 😁 😆';
$result = $emoji->find($stringWithEmoji); // ['😀', '😃', '😄', '😁', '😆']
```---
# How to create custom delimiter
Create delimiter class that implements `\Anisimov\Emoji\Delimiter\DelimiterInterface`.
`\Anisimov\Emoji\Delimiter\DelimiterInterface::getRegexp` method should return regex to find delimiter wrapped emoji.
`\Anisimov\Emoji\Delimiter\DelimiterInterface::getDelimiter` method should return delimiter symbols
For example, `\Anisimov\Emoji\Delimiter\SingleColonDelimiter`
`\Anisimov\Emoji\Delimiter\SingleColonDelimiter::getRegexp` returns `/[\:]{1}[^(\:|\s)]{1,}[\:]{1}/`
`\Anisimov\Emoji\Delimiter\SingleColonDelimiter::getDelimiter` returns `:`