itsnubix / emoji
一个用于与表情符号交互的PHP库
v0.0.0
2022-06-17 16:51 UTC
Requires
- php: ^8.1
Requires (Dev)
- pestphp/pest: ^1.21
- pestphp/pest-plugin-faker: ^1.0
README
为PHP添加了对插入和转换表情符号到Unicode的支持。使用枚举类型,因此需要PHP8.1或更高版本。
安装
composer require itsnubix/emoji
使用方法
下面是一些使用示例。
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 👋🏻"
要查看支持的完整表情符号列表以及支持添加肤色的表情符号,请参阅:Character
要查看完整的肤色列表,请参阅:SkinTone
待办事项
- 允许用户选择表情符号
- 允许用户设置肤色
- 添加对所有表情符号肤色的支持
- 添加在替换字符串时更改肤色的支持