1 回答

TA貢獻(xiàn)2037條經(jīng)驗 獲得超6個贊
Intl 擴(kuò)展提供了處理 unicode代碼點(diǎn)和塊的函數(shù),這些函數(shù)將允許您確定當(dāng)前字符是否是表情符號。
function emoji_to_unicode($emoji) {
$emoji = mb_convert_encoding($emoji, 'UTF-32', 'UTF-8');
$unicode = strtoupper(preg_replace("/^[0]{3}/","U+",bin2hex($emoji)));
return $unicode;
}
$var = ("??x??text here");
$out = '';
for ($i = 0; $i < mb_strlen($var); $i++) {
$char = mb_substr($var, $i, 1);
$isEmoji = IntlChar::getBlockCode(IntlChar::ord($char)) == IntlChar::BLOCK_CODE_EMOTICONS;
$out .= $isEmoji ? emoji_to_unicode($char) : $char;
}
echo $out;
這是您可以在其中找到所有塊的預(yù)定義常量列表。
- 1 回答
- 0 關(guān)注
- 279 瀏覽
添加回答
舉報