来自 Twitter 的开发者文档:对于具有Unicode处理经验的程序员来说,这个问题的简短答案是,推文长度是通过文本的NFC规范化版本中的码位数来衡量的。因此,要计算PHP中推文的长度,您将首先使用规范化表单C(NFC)规范化文本,然后计算规范化文本中的码位(不是字符)的数量。$text = "👍🏿✌🏿️ @mention";// Get the normalized text in UTF-8$NormalizedText = Normalizer::normalize($text, Normalizer::FORM_C );// Now we can calculate the number of codepoints in this normalized text$it = IntlBreakIterator::createCodePointInstance();$it->setText($NormalizedText);$len = 0;foreach ($it as $codePoint) { $len++;}echo "Length = $len"; // Result: Length = 15