* @return bool
*/
public static function isUtf8($str) {
- if (!function_exists(mb_detect_encoding)) {
- // eliminate all white space from the string
- $str = preg_replace('/\s+/', '', $str);
-
- // pattern stolen from the php.net function documentation for
- // utf8decode();
- // comment by JF Sebastian, 30-Mar-2005
- return preg_match('/^([\x00-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xec][\x80-\xbf]{2}|\xed[\x80-\x9f][\x80-\xbf]|[\xee-\xef][\x80-\xbf]{2}|f0[\x90-\xbf][\x80-\xbf]{2}|[\xf1-\xf3][\x80-\xbf]{3}|\xf4[\x80-\x8f][\x80-\xbf]{2})*$/', $str);
- // ||
- // iconv('ISO-8859-1', 'UTF-8', $str);
- }
- else {
- $enc = mb_detect_encoding($str, ['UTF-8'], TRUE);
- return ($enc !== FALSE);
- }
+ $enc = mb_detect_encoding($str, ['UTF-8'], TRUE);
+ return ($enc !== FALSE);
}
/**