本文整理汇总了PHP中utf8::loadCharset方法的典型用法代码示例。如果您正苦于以下问题:PHP utf8::loadCharset方法的具体用法?PHP utf8::loadCharset怎么用?PHP utf8::loadCharset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utf8
的用法示例。
在下文中一共展示了utf8::loadCharset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
define("CP1258", MAP_DIR . "/CP1258.MAP");
define("CP874", MAP_DIR . "/CP874.MAP");
define("CP932", MAP_DIR . "/CP932.MAP");
define("CP936", MAP_DIR . "/CP936.MAP");
define("CP949", MAP_DIR . "/CP949.MAP");
define("CP950", MAP_DIR . "/CP950.MAP");
define("GB2312", MAP_DIR . "/GB2312.MAP");
define("BIG5", MAP_DIR . "/BIG5.MAP");
$utfConverter = new utf8(CP1251);
//defaults to CP1250.
$utfConverter->loadCharset(CP1256);
$utfConverter_ru = new utf8(CP1251);
//defaults to CP1250.
$utfConverter_ru->loadCharset(CP1251);
$utfConverter_ch = new utf8(GB2312);
$utfConverter_ch->loadCharset(GB2312);
/***************************************************/
/***************************************************/
/***************************************************/
$dominio = $_SERVER['SERVER_NAME'];
switch ($dominio) {
case 'www.catedu.es':
$url_dominio = 'www.catedu.es/arasaac';
break;
case 'catedu.es':
$url_dominio = 'catedu.es/arasaac';
break;
case 'www.arasaac.org':
$url_dominio = 'www.arasaac.org';
break;
case 'arasaac.org':
示例2: convert
/**
* Convert a string from one charset to another.
* Uses mbstring and iconv functions if possible
*
* @param string Input string
* @param string Suspected charset of the input string
* @param string Target charset to convert to; defaults to RCMAIL_CHARSET
*
* @return string Converted string
*/
public static function convert($str, $from, $to = null)
{
static $iconv_options = null;
static $mbstring_loaded = null;
static $mbstring_list = null;
static $conv = null;
$to = empty($to) ? strtoupper(RCMAIL_CHARSET) : $to;
$from = self::parse($from);
// It is a common case when UTF-16 charset is used with US-ASCII content (#1488654)
// In that case we can just skip the conversion (use UTF-8)
if ($from == 'UTF-16' && !preg_match('/[^\\x00-\\x7F]/', $str)) {
$from = 'UTF-8';
}
if ($from == $to || empty($str) || empty($from)) {
return $str;
}
// convert charset using iconv module
if (function_exists('iconv') && $from != 'UTF7-IMAP' && $to != 'UTF7-IMAP') {
if ($iconv_options === null) {
// ignore characters not available in output charset
$iconv_options = '//IGNORE';
if (iconv('', $iconv_options, '') === false) {
// iconv implementation does not support options
$iconv_options = '';
}
}
// throw an exception if iconv reports an illegal character in input
// it means that input string has been truncated
set_error_handler(array('rcube_charset', 'error_handler'), E_NOTICE);
try {
$_iconv = iconv($from, $to . $iconv_options, $str);
} catch (ErrorException $e) {
$_iconv = false;
}
restore_error_handler();
if ($_iconv !== false) {
return $_iconv;
}
}
if ($mbstring_loaded === null) {
$mbstring_loaded = extension_loaded('mbstring');
}
// convert charset using mbstring module
if ($mbstring_loaded) {
$aliases['WINDOWS-1257'] = 'ISO-8859-13';
if ($mbstring_list === null) {
$mbstring_list = mb_list_encodings();
$mbstring_list = array_map('strtoupper', $mbstring_list);
}
$mb_from = $aliases[$from] ? $aliases[$from] : $from;
$mb_to = $aliases[$to] ? $aliases[$to] : $to;
// return if encoding found, string matches encoding and convert succeeded
if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list)) {
if (mb_check_encoding($str, $mb_from) && ($out = mb_convert_encoding($str, $mb_to, $mb_from))) {
return $out;
}
}
}
// convert charset using bundled classes/functions
if ($to == 'UTF-8') {
if ($from == 'UTF7-IMAP') {
if ($_str = self::utf7imap_to_utf8($str)) {
return $_str;
}
} else {
if ($from == 'UTF-7') {
if ($_str = self::utf7_to_utf8($str)) {
return $_str;
}
} else {
if ($from == 'ISO-8859-1' && function_exists('utf8_encode')) {
return utf8_encode($str);
} else {
if (class_exists('utf8')) {
if (!$conv) {
$conv = new utf8($from);
} else {
$conv->loadCharset($from);
}
if ($_str = $conv->strToUtf8($str)) {
return $_str;
}
}
}
}
}
}
// encode string for output
if ($from == 'UTF-8') {
// @TODO: we need a function for UTF-7 (RFC2152) conversion
//.........这里部分代码省略.........