Page MenuHomePhorge
Diviner libphutil Tech Docs phutil_utf8_console_strlen

function phutil_utf8_console_strlen($string)
libphutil Technical Documentation (Core Utilities)

Find the console display length of a UTF-8 string. This may differ from the character length of the string if it contains double-width characters, like many Chinese characters.

This method is based on a C implementation here, which is based on the IEEE standards. The source has more discussion and addresses more considerations than this implementation does.

http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
NOTE: We currently assume width 1 for East-Asian ambiguous characters.
NOTE: This function is VERY slow.
Parameters
string$stringA valid UTF-8 string.
Return
intThe console display length of the string.