Changeset View
Changeset View
Standalone View
Standalone View
src/utils/utf8.php
Show First 20 Lines • Show All 282 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Find the character length of a UTF-8 string. | * Find the character length of a UTF-8 string. | ||||
* | * | ||||
* @param string A valid utf-8 string. | * @param string A valid utf-8 string. | ||||
* @return int The character length of the string. | * @return int The character length of the string. | ||||
*/ | */ | ||||
function phutil_utf8_strlen($string) { | function phutil_utf8_strlen($string) { | ||||
if (function_exists('utf8_decode')) { | |||||
return strlen(utf8_decode($string)); | |||||
} | |||||
return count(phutil_utf8v($string)); | return count(phutil_utf8v($string)); | ||||
} | } | ||||
/** | /** | ||||
* Find the console display length of a UTF-8 string. This may differ from the | * 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 | * character length of the string if it contains double-width characters, like | ||||
* many Chinese characters. | * many Chinese characters. | ||||
▲ Show 20 Lines • Show All 685 Lines • Show Last 20 Lines |