Home > PHP Framework > Laravel > body text

How to integrate and use Emoji expressions in Laravel applications

藏色散人
Release: 2020-04-23 13:41:56
forward
2215 people have browsed it

Laravel Emoji - Integrate and use Emoji expressions in Laravel applications

How to 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(&#39;"\uD83D\uDE00"&#39;);
Copy after login

PHP 7 provides better support for Unicode strings, and we can display emoticons more conveniently:

<?php
echo "\u{1F60E}";
Copy after login

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
Copy after login

To install the latest version of Laravel Emoji, declare the following dependencies in composer.json:

"unicodeveloper/laravel-emoji": "1.0.*"
Copy after login

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
Copy after login

At the same time, don’t forget to register the facade to the aliases array. :

&#39;aliases&#39; => [    
    ...    
    &#39;Emoji&#39; => Unicodeveloper\Emoji\Facades\Emoji::class,
    ...
]
Copy after login

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 &#39;blush&#39;
Copy after login

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!

Related labels:
source:xueyuanjun.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!