From Twitter's developer documentation:
For programmers with experience in Unicode processing the short answer to the question is that Tweet length is measured by the number of codepoints in the NFC normalized version of the text.
So to calculate the length of a tweet in PHP, you would first normalize the text using Normalization Form C (NFC) and then count the number of codepoints (NOT CHARACTERS) in the normalized text.
$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