PHP code example of itsnubix / emoji

1. Go to this page and download the library: Download itsnubix/emoji library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

itsnubix / emoji example snippets


use Emoji\Emoji;
use Emoji\SkinTone;

// Globally set skin tone for all applicable emojis
Emoji::setDefaultSkinTone(SkinTone::medium);

// Various methods for spitting out a unicode emoji
Emoji::get('grinning_face')->toString(); // returns 😀
(string) Emoji::grinning_face(); // returns 😀
echo Emoji::grinningFace(); // returns 😀

// Overwrite the default skin tone on the fly
Emoji::get('waving_hand', SkinTone::light)->toString(); // returns 👋🏻
Emoji::wavingHand()->light()->toString(); // returns 👋🏻
Emoji::wavingHand()->skinTone('light')->toString(); // returns 👋🏻

// Also supports dynamic skin tone selection with a callback
$user = new User(['preferred_skin_tone' => SkinTone::light])
Emoji::wavingHand()
  ->skinTone(fn() => $user->preferred_skin_tone)
  ->toString();

// You may also remove tone from a given emoji as well.
$emoji = Emoji::wavingHand(SkinTone::medium);
$emoji->skinTone(); // get the skin tone, returns SkinTone::medium
$emoji->toneless()->skinTone(); // returns null

// Finally, you may replace emojis in a string where they match within
// two colons and align to an allowed emoji character. If invalid characters
// are used it just returns them without converting
Emoji::parse('Hello world :waving_hand: how are you :invalid_character:'); // returns "Hello world 👋" how are you :invalid_character:"

// You can set the skin tone for the parser globally with...
Emoji::setDefaultSkinTone(Emoji::light);
Emoji::parse('Hello world :waving_hand:'); // returns "Hello world 👋🏻"