emoji php
ve parser and tests
統一碼版本: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偵測給定字串是否包含一個或多個表情符號字元。
onlyEmoji($string, $ignoreWhitespace = true): bool偵測給定字串是否僅包含表情符號字元。
此方法忽略任何空格、製表符和其他空白字元 ( s )。將false傳遞給第二個參數以不忽略空白字元。
removeEmoji($string): string傳回刪除所有表情符號字元的給定字串。
allEmojis($string): array傳回輸入字串的所有表情符號的陣列。
startingEmojis($string, $ignoreWhitespace = true): array傳回輸入字串的起始表情符號陣列。
此方法忽略任何空格、製表符和其他空白字元 ( s )。將false傳遞給第二個參數以不忽略空白字元。
運行簡單的測試:
php test/tests.php預期輸出:
Tests total: 119
run: 119
succeeded: 119
failed: 0