hidehalo / emoji
过滤emoji符号供您使用
1.0.1
2018-03-16 14:06 UTC
Requires (Dev)
- phpunit/phpunit: >=5.7
This package is auto-updated.
Last update: 2024-08-27 10:40:56 UTC
README
如果您想帮助解析和存储emoji符号字符,您可以考虑使用这个库 :)
特性
- 仅检测emoji符号
- 将emoji符号替换为其他文本并恢复
- 无依赖
- 轻量级且快速
安装
$composer require hidehalo/emoji
使用方法
解析器
require vendor/autoload.php; use Hidehalo\Emoji\Parser; $parser = new Parser(); $parser->parse($contents);
转换器
# if you want to replace those emoji symbols to ohter marked texts # and has ability to turn those back, # it has a built-in Protocol and Converter could do this # and $decoded will equals $raw,it is real very simple use Hidehalo\Emoji\Converter; $converter = new Converter($parser); $encoded = $converter->encode($raw); $decoded = $converter->decode($encoded); # filter emojis use Hidehalo\Emoji\Protocol\Filter; $clean = $converter->encode($raw, new Filter);
自定义协议
也许您想实现自定义转换协议,您可以通过实现ProtocolInterface来完成
use Hidehalo\Emoji\Protocol\ProtocolInterface as Protocol; use Hidehalo\Emoji\Protocol\PatternAwareTrait; class CustomProto implments Protocol { use PatternAwareTrait; protected $format = "FORMAT"; protected $pattern = "/FORMAT/"; public function encode($contents) { //your impls } public function decode($contents) { //your impls } } $customProto = new CustomProto; $customEncoded = $converter->encode($raw, $customProto); $customDecoded = $converter->decode($customDecoded, $customProto);
测试
$./vendor/bin/phpunit
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。