Changeset View
Changeset View
Standalone View
Standalone View
src/utils/utf8.php
Show First 20 Lines • Show All 283 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')) { | if (function_exists('utf8_decode')) { | ||||
return strlen(utf8_decode($string)); | return strlen(mb_convert_encoding($string, 'ISO-8859-1')); | ||||
} | } | ||||
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 | ||||
▲ Show 20 Lines • Show All 686 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0