Pemojine is a library for handling Emoji in PHP.
This library is getting data from here.
- Full Emoji List, v13.1
- Full Emoji Modifier Sequences, v13.1
- emoji-toolkit/emoji.json at master · joypixels/emoji-toolkit
- Support for php5.5-7.3
- Treat one Emoji as a group.
- MediumGroup bundle Groups.
- BigGroup bundle MediumGroups.
- Vendor bundle BigGroups.
- @see Full Emoji List, v13.1
- You can output it for each vendor (Apple, Google, etc...).
- Outputable for each group.
- BigGroups, MediumGroups, Groups.
- Randomly output Emoji.
- Create sentences containing Emoji.
- The group structure can be easily customized.
- Todo
Via Composer
$ composer require shimabox/pemojine
Develop
$ git clone https://github.com/shimabox/pemojine
$ cd pemojine
$ composer install
<?php
require_once 'vendor/autoload.php';
use SMB\Pemojine\Container as PemojineContainer;
use SMB\Pemojine\Structure\Vendor;
use SMB\Pemojine\Helper\Sentence;
// Create an instance of Google using a Container.
$pemojine = PemojineContainer::make(new Vendor\Google());
// Get the configured vendor name.
echo $pemojine->getVendorName(); // => Google
/*
|----------------------------------------------------------------------
| Get all BigGroups.
|----------------------------------------------------------------------
*/
$allBigGroups = $pemojine->getAllBigGroups();
// $allBigGroups is an array with a big group name in the key and an object(BigGroup) in the value.
foreach ($allBigGroups as $bigGroupName => $bigGroup) {
echo 'BigGroupName::' . $bigGroupName/* or $bigGroup->getName() */;
foreach ($bigGroup as $mediumGroupName => $mediumGroup) {
echo 'MediumGroupName::' . $mediumGroupName/* or $mediumGroup->getName() */;
foreach ($mediumGroup as $groupName => $group) {
// Output shortName.
echo 'Group::' . $groupName/* or $group->getName(), $group->getShortName() */;
// Output Emoji.
echo $group->output();
// Output HTML reference character. e.g) '😀', '🇯🇵'
echo htmlspecialchars($group->outputHtml(), ENT_QUOTES, 'UTF-8');
// Get unicode. e.g.) 'U+1F600', 'U+1F1EF U+1F1F5'
echo $group->getUnicode();
// Get unicode with removed blank. e.g.) 'U+1F600', 'U+1F1EFU+1F1F5'
echo $group->getUnicodeWithRemovedBlank();
// Get UTF8 string. e.g.) '\u{1F600}', '\u{1F1EF} \u{1F1F5}'
echo $group->getUtf8String();
// Get UTF8 string with removed blank. e.g.) '\u{1F600}', '\u{1F1EF}\u{1F1F5}'
echo $group->getUtf8StringWithRemovedBlank();
// Get aliases of shortName
$alias = implode(' ', $group->getAliasesOfName()/* or $group->getAliasesOfShortName() */);
echo htmlspecialchars($alias, ENT_QUOTES, 'UTF-8');
}
}
}
/*
|----------------------------------------------------------------------
| When selecting randomly from Big Groups.
|----------------------------------------------------------------------
*/
// Select a BigGroup at random
$randomBigGroup = $pemojine->randomFromBigGroup();
echo $randomBigGroup->getName(); // Randomly chosen BigGroupName.
// When acquiring a random group from narrowed down.
$groupOfBig = $randomBigGroup->getGroupAtRandom();
echo $groupOfBig->getName();
$alias = implode(' ', $groupOfBig->getAliasesOfName());
echo htmlspecialchars($alias, ENT_QUOTES, 'UTF-8');
echo $groupOfBig->output();
echo htmlspecialchars($groupOfBig->outputHtml(), ENT_QUOTES, 'UTF-8');
echo $groupOfBig->getUnicode();
echo $groupOfBig->getUnicodeWithRemovedBlank();
echo $groupOfBig->getUtf8String();
echo $groupOfBig->getUtf8StringWithRemovedBlank();
/*
|----------------------------------------------------------------------
| When selecting 'animal-mammal' in Medium Groups.
|----------------------------------------------------------------------
*/
// Select 'animal-mammal'.
$selectedMediumGroup = $pemojine->selectMediumGroup('animal-mammal');
echo $selectedMediumGroup->getVendorName(); // => 'Google'
echo $selectedMediumGroup->getName(); // => 'animal-mammal'
// $selectedMediumGroup is an iterator with a group name in the key and an object(Group) in the value.
foreach ($selectedMediumGroup/* or $selectedMediumGroup->getChildren() */ as $groupName => $group) {
echo 'Group::' . $groupName;
echo $group->output();
echo htmlspecialchars($group->outputHtml(), ENT_QUOTES, 'UTF-8');
echo $group->getUnicode();
echo $group->getUnicodeWithRemovedBlank();
echo $group->getUtf8String();
echo $group->getUtf8StringWithRemovedBlank();
$alias = implode(' ', $group->getAliasesOfName());
echo htmlspecialchars($alias, ENT_QUOTES, 'UTF-8');
}
// When acquiring a random group from narrowed down.
$groupOfM = $selectedMediumGroup->getGroupAtRandom();
echo $groupOfM->getName()/* or $groupOfM->getShortName() */;
$alias = implode(' ', $groupOfM->getAliasesOfName()/* or $groupOfM->getAliasesOfShortName() */);
echo htmlspecialchars($alias, ENT_QUOTES, 'UTF-8');
echo $groupOfM->output();
echo htmlspecialchars($groupOfM->outputHtml(), ENT_QUOTES, 'UTF-8');
echo $groupOfM->getUnicode();
echo $groupOfM->getUnicodeWithRemovedBlank();
echo $groupOfM->getUtf8String();
echo $groupOfM->getUtf8StringWithRemovedBlank();
// In the case of Medium Group, you can find a Big Group of parents.
$parent = $pemojine->selectMediumGroup('animal-mammal')->findParentGroup(); // => Parent BigGroup
assert($parent->getName() === 'Animals & Nature'); // => true
// The following are the same instances.
$a = $pemojine->selectBigGroup('Animals & Nature')->selectMediumGroup('animal-mammal');
$b = $pemojine->selectMediumGroup('animal-mammal');
assert($a === $b); // => true
// Exists?
assert($pemojine->hasMediumGroup('animal-bird') === true);
assert($pemojine->hasMediumGroup('piyo') === false);
/*
|----------------------------------------------------------------------
| Create sentences including Emoji.
|----------------------------------------------------------------------
*/
// Get an Outputter instance.
$outputter = $pemojine->getOutputter();
// Other ways to get instances.
/*
// Create an EmojiTable instance of Apple.
$emojiTable = new \SMB\Pemojine\Structure\Vendor\Apple\EmojiTable();
// Create an Outputter instance.
$outputter = new \SMB\Pemojine\Outputter\Outputter($emojiTable);
*/
// Create a Sentence instance.
$sentence = new Sentence($outputter);
// Sentence 1
$output_1 = $sentence->create('Hello U+1F1EFU+1F1F5 \u{1F601}:grin:|beaming face with smiling eyes|!!');
assert('Hello 🇯🇵 😁😁😁!!' === $output_1);
echo $output_1;
// Sentence 2
$output_2 = $sentence->create('foo ::heart:: :bar:cinema:baz:');
assert('foo :❤: :bar🎦baz:' === $output_2);
echo $output_2;
// Sentence 3
$output_3 = $sentence->create('foo ||grinning face with big eyes|| |bar|face with tears of joy|baz|');
assert('foo |😃| |bar😂baz|' === $output_3);
echo $output_3;
Create three files below.
- Files that implements
SMB\Pemojine\Structure\Interfaces\Configurable
. - Files that implements
SMB\Pemojine\Structure\Interfaces\Gettable
. - Files that implements
SMB\Pemojine\Structure\Interfaces\EmojiTable\Gettable
.
@see example/Custom
- example/getAll.php
$ php example/getAll.php
- example/selectAtRandom.php
$ php example/selectAtRandom.php
- example/selectGroup.php
$ php example/selectGroup.php
- example/outputter.php
$ php example/outputter.php
- example/helper_converter.php
$ php example/helper_converter.php
- example/helper_emoji.php
$ php example/helper_emoji.php
- example/helper_emojiCounter.php
$ php example/helper_emojiCounter.php
- example/helper_sentence.php
$ php example/helper_sentence.php
- example/Custom/example.php
$ php example/Custom/example.php
$ php scraping/src/generator.php
Scrape the data here.
(The result is cached for 1 hour in scraping/cache/full-emoji-list
, scraping/cache/full-emoji-modifiers
)
- Full Emoji List, v13.1
- Full Emoji Modifier Sequences, v13.1
- emoji-toolkit/emoji.json at master · joypixels/emoji-toolkit
scraping/output/Config
, scraping/output/Structure
Since files are output below, please place them under src/Config
, src/Structure
respectively.
- For Mac(Linux).
$ sh scraping/sync.sh
- For Windows.
$ cd scraping/
$ win_sync.bat
$ composer test # or vendor/bin/phpunit
- Coverage
$ composer coverage # or vendor/bin/phpunit --coverage-text --coverage-html ./report/
- Make a demo site.
- Regular expressions that make up sentences with Emoji are rough.
- pemojine/Sentence.php at master · shimabox/pemojine.
- I tried to cope with nesting.
- But it does not correspond to complex nesting.
- Emoji mapping(array) is too rich, so I need to think about this.
- For
Vendor\JoyPixels
I feel correct to combine with emoji-toolkit/lib/php at master · joypixels/emoji-toolkit. - Confirmation on actual machine.
The MIT License (MIT). Please see License File for more information.