maximal/emoji

无依赖项的 Emoji 检测和处理

v1.7 2023-05-04 15:49 UTC

This package is auto-updated.

Last update: 2024-09-04 18:37:17 UTC


README

Unicode 版本:15.0。

安装

使用 Composer require 命令安装此库

composer require maximal/emoji '^1.0'

或将包名添加到您的 composer.json 文件的 require 部分中

"require": {
	"maximal/emoji": "^1.0"
}

然后运行

composer update

然后在您的代码的任何位置包含 Composer 自动加载

require_once __DIR__ . '/vendor/autoload.php';

用法

use Maximal\Emoji\Detector;

// Whether the given string contains emoji characters
$isEmojiFound = Detector::containsEmoji($string);
// 'test' -> false
// 'test 👍' -> true

// Whether the given string consists of emoji characters only
$isEmojiOnly = Detector::onlyEmoji($string);
// 'test 👍' -> false
// '👍😘' -> true

// String without any emoji character
$stringWithoutEmoji = Detector::removeEmoji($string);
// 'test 👍' -> 'test '
// '👍😘' -> ''

// All emojis of the string
$allEmojis = Detector::allEmojis($string);
// 'test 👍' -> ['👍']
// '👍😘' -> ['👍', '😘']

// Starting emojis of the string
$startingEmojis = Detector::startingEmojis($string);
// '👍😘 test' -> ['👍', '😘']
// 'test 👍' -> []

containsEmoji($string): bool

检测给定的字符串是否包含一个或多个 emoji 字符。

onlyEmoji($string, $ignoreWhitespace = true): bool

检测给定的字符串是否只包含 emoji 字符。

此方法忽略任何空格、制表符和其他空白字符(\s)。将第二个参数传递为 false 以不忽略空白字符。

removeEmoji($string): string

返回移除所有 emoji 字符的给定字符串。

allEmojis($string): array

返回输入字符串中所有 emoji 的数组。

startingEmojis($string, $ignoreWhitespace = true): array

返回输入字符串的起始 emoji 数组。

此方法忽略任何空格、制表符和其他空白字符(\s)。将第二个参数传递为 false 以不忽略空白字符。

测试

运行简单测试

php test/tests.php

预期输出

Tests total:  119
        run:  119
  succeeded:  119
     failed:  0

联系作者