PHP code example of aksafan / yii2-emoji-detection

1. Go to this page and download the library: Download aksafan/yii2-emoji-detection 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/ */

    

aksafan / yii2-emoji-detection example snippets


return [
    //....
    'components' => [
        'emojiDetector' => [
             'class' => 'aksafan\emoji\source\EmojiDetector\EmojiDetector',
        ],
    ]
];

/**
 * Class WebApplication
 * Include only Web application related components here.
 *
 * @property \aksafan\emoji\source\EmojiDetector $emojiDetector
 */
class WebApplication extends yii\web\Application
{
}

Yii::$app->emojiDetector

$input = "Hello 👍🏼 World 👨‍👩‍👦‍👦";
$emoji = Yii::$app->emojiDetector->detectAll($input);

print_r($emoji);

$input = "Hello 👍🏼 World 👨‍👩‍👦‍👦";
$emoji = Yii::$app->emojiDetector->detectAllWIthSingleParam($input, aksafan\emoji\source\EmojiDetector::EMOJI);

print_r($emoji);

$input = "Hello 👍🏼 World 👨‍👩‍👦‍👦";
$emoji = Yii::$app->emojiDetector->detectAllWIthSingleParam($input, aksafan\emoji\source\EmojiDetector::SHORT_NAME);

print_r($emoji);

$input = "Hello 👍🏼 World 👨‍👩‍👦‍👦";
$emoji = Yii::$app->emojiDetector->replaceEmojis($input); //Default replacer is ''
// "Hello  World "

$input = "Hello 👍🏼 World 👨‍👩‍👦‍👦";
$emoji = Yii::$app->emojiDetector->replaceEmojis($input, '1');
// "Hello 1 World 1"

$input = "0️⃣5️⃣5️⃣0️⃣";
$emoji = Yii::$app->emojiDetector->replaceEmojis($input, '2');
// "2222"

$input = "Hello 👍🏼 World 👨‍👩‍👦‍👦";
$emoji = Yii::$app->emojiDetector->countEmojis($input);
// 2

$input = "0️⃣5️⃣5️⃣0️⃣";
$emoji = Yii::$app->emojiDetector->countEmojis($input);
// 4

$emoji = Yii::$app->emojiDetector->isSingleEmoji('👨‍👩‍👦‍👦');
// true

$emoji =Yii::$app->emojiDetector->isSingleEmoji('Emoji with text 👨‍👩‍👦‍👦');
// false

$emoji =Yii::$app->emojiDetector->isSingleEmoji('😻🐈');
// false

$emoji = Yii::$app->emojiDetector->isEmoji('👨‍👩‍👦‍👦');
// true

$emoji =Yii::$app->emojiDetector->isEmoji('Emoji with text 👨‍👩‍👦‍👦');
// true

$emoji =Yii::$app->emojiDetector->isEmoji('😻🐈');
// true

$emoji =Yii::$app->emojiDetector->isEmoji('Just text');
// false

$emoji = Yii::$app->emojiDetector->getEmojiMap();

print_r($emoji);

$emoji = Yii::$app->emojiDetector->getEmojiRegexp();
// "/(?:\x{1F468}\x{200D}\x{2764}\x{FE0F}\x{200D}\x{1F48B}\x{200D}\x{1F468}|\x{1F469}\x{200D}\x{2764}\x{FE0F}\x{200D}\x{1F48B}\x{200D}\x{1F469}|\x{1F469}\x{200D}\x{2764}\x{FE0F}\x{200D}\x{1F48B}\x{200D}\x{1F468}|\x{1F3F4}\x{E0067}\x{E0062}\x{E0073}\x{E0063}\x{E0074}\x{E007F}|\x{1F3F4}\x{E0067}\x{E0062}\x{E0065}\x{E006E}\x{E0067}\x{E007F}|\x{1F3F4}\x{E0067}\x{E0062}\x{E0077}\x{E006C}\x{E0073}\x{E007F}...)"

$ php composer.phar