/** * This function returns an array of those languages that can use Latin 1 encoding. * Appendix to "Language support" * @return array The array of languages that can use Latin 1 encoding (ISO-8859-15, ISO-8859-1, WINDOWS-1252, ...). * Note: The returned language identificators are purified, without suffixes. */ function _api_get_latin1_compatible_languages() { static $latin1_languages; if (!isset($latin1_languages)) { $latin1_languages = array(); $encodings =& _api_non_utf8_encodings(); foreach ($encodings as $key => $value) { if (api_is_latin1($value[0])) { $latin1_languages[] = $key; } } } return $latin1_languages; }
/** * Converts a given string from UTF-8 encoding to a specified encoding. * @param string $string The string being converted. * @param string $to_encoding (optional) The encoding that $string is being converted to. If it is omited, the platform character set is assumed. * @return string Returns the converted string. * This function is aimed at replacing the function utf8_decode() for human-language strings. * @link http://php.net/manual/en/function.utf8-decode */ function api_utf8_decode($string, $to_encoding = null) { if (empty($to_encoding)) { $to_encoding = _api_mb_internal_encoding(); } if (api_is_utf8($to_encoding)) { return $string; // When conversion is not needed, the string is returned directly, without validation. } if (_api_mb_supports($to_encoding)) { return @mb_convert_encoding($string, $to_encoding, 'UTF-8'); } if (_api_iconv_supports($to_encoding)) { return @iconv('UTF-8', $to_encoding, $string); } if (api_is_latin1($to_encoding, true)) { return utf8_decode($string); } if (_api_convert_encoding_supports($to_encoding)) { return _api_convert_encoding($string, $to_encoding, 'UTF-8'); } return $string; // Here the function gives up. }