Changeset View
Changeset View
Standalone View
Standalone View
src/utils/utf8.php
| Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Determine if a string is valid UTF-8. | * Determine if a string is valid UTF-8. | ||||
| * | * | ||||
| * @param string Some string which may or may not be valid UTF-8. | * @param string Some string which may or may not be valid UTF-8. | ||||
| * @return bool True if the string is valid UTF-8. | * @return bool True if the string is valid UTF-8. | ||||
| */ | */ | ||||
| function phutil_is_utf8($string) { | function phutil_is_utf8($string) { | ||||
| if (function_exists('mb_check_encoding')) { | if (function_exists('mb_check_encoding')) { | ||||
| // See T13527. In some versions of PHP, "mb_check_encoding()" strictly | |||||
| // requires a string parameter. | |||||
| $string = phutil_string_cast($string); | |||||
| // If mbstring is available, this is significantly faster than using PHP. | // If mbstring is available, this is significantly faster than using PHP. | ||||
| return mb_check_encoding($string, 'UTF-8'); | return mb_check_encoding($string, 'UTF-8'); | ||||
| } | } | ||||
| return phutil_is_utf8_slowly($string); | return phutil_is_utf8_slowly($string); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 873 Lines • Show Last 20 Lines | |||||