hidehalo/emoji

过滤emoji符号供您使用

维护者

详细信息

github.com/hidehalo/Emoji

源代码

问题

安装数: 122 373

依赖: 0

建议者: 0

安全: 0

星标: 31

关注者: 4

分支: 2

1.0.1 2018-03-16 14:06 UTC

This package is auto-updated.

Last update: 2024-08-27 10:40:56 UTC


README

Build Status FOSSA Status

如果您想帮助解析和存储emoji符号字符,您可以考虑使用这个库 :)

特性

  1. 仅检测emoji符号
  2. 将emoji符号替换为其他文本并恢复
  3. 无依赖
  4. 轻量级且快速

安装

$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)。请参阅许可证文件以获取更多信息。

FOSSA Status