You can get the number of UTF-8 code points inside a PHP binary string (provided that it is valid in UTF-8 encoding) ( Demo ):
$length = preg_match_all('(.)su', $subject);
You can also use the multibyte extension if it is installed:
$length = mb_strlen($subject, 'UTF-8');
See also: PHP UTF-8 String
source share