Home >PHP Framework >Laravel >How to integrate and use Emoji expressions in Laravel applications
Laravel Emoji - Integrate and use Emoji expressions in Laravel applications
1. Introduction
Social networks are so developed Today, Emoji expression packs are everywhere, whether it is QQ, WeChat, Weibo or major forums, they are everywhere. As a developer, you may need to provide a variety of emoticons in your application for users to use when commenting and communicating.
PHP 5 already supports converting Unicode strings into emoticons, but it is more complicated:
<?php echo json_decode('"\uD83D\uDE00"');
PHP 7 provides better support for Unicode strings, and we can display emoticons more conveniently:
<?php echo "\u{1F60E}";
Of course, such coding is unfriendly. We need to use a more readable way to implement emoticon display. Fortunately, in Laravel, we can achieve this through the Laravel Emoji extension package this purpose.
2. Installation
System requirements:
PHP 7.0+/HHVM 3.3+,Composer
To install the latest version of Laravel Emoji, declare the following dependencies in composer.json:
"unicodeveloper/laravel-emoji": "1.0.*"
Then run composer install or composer update to download and install the extension package.
After the installation is completed, you need to register the service provider. In the configuration file app.php, add the following code to the providers array:
Unicodeveloper\Emoji\EmojiServiceProvider::class
At the same time, don’t forget to register the facade to the aliases array. :
'aliases' => [ ... 'Emoji' => Unicodeveloper\Emoji\Facades\Emoji::class, ... ]
3. Use
Laravel Emoji provides us with a variety of ways to display expressions, and then call them uniformly through the Emoji facade:
<?php Emoji::findByAlias("kissing_heart"); Emoji::findByName("sunglasses"); Emoji::findByUnicode("\u{1F60A}"); //displays 'blush'
For more Emoji expressions, please view Complete Emoji Expression List.
Original address: https://xueyuanjun.com/post/3548
The above is the detailed content of How to integrate and use Emoji expressions in Laravel applications. For more information, please follow other related articles on the PHP Chinese website!