本文整理匯總了PHP中utf8::trans_table方法的典型用法代碼示例。如果您正苦於以下問題:PHP utf8::trans_table方法的具體用法?PHP utf8::trans_table怎麽用?PHP utf8::trans_table使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utf8
的用法示例。
在下文中一共展示了utf8::trans_table方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: init
public static function init()
{
self::$utf8validator = (bool) extension_loaded('utf8validator');
mb_internal_encoding('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
mb_detect_order(array('UTF-8', 'ISO-8859-1'));
mb_substitute_character(0xfffd);
MCached::connect();
$trans = MCached::get(self::TRANSKEY);
if ($trans === MCached::NO_RESULT) {
$win = "€" . implode('', range("‚", "Œ")) . "Ž" . implode('', range("‘", "œ")) . implode('', range("ž", "ÿ"));
$win_iso = "�����";
$iso = implode('', range("€", "ÿ"));
$winlen = strlen($win);
$winisolen = strlen($win_iso);
$isolen = strlen($iso);
$trans = array('iso_to_utf8' => array(), 'win_to_utf8' => array(), 'from_utf8' => array());
for ($i = 0; $i < $isolen; $i++) {
$utf8 = mb_convert_encoding($iso[$i], 'UTF-8', 'ISO-8859-1');
$trans['iso_to_utf8'][$iso[$i]] = $utf8;
$trans['from_utf8'][$utf8] = $iso[$i];
}
for ($i = 0; $i < $winlen; $i++) {
$utf8 = mb_convert_encoding($win[$i], 'UTF-8', 'Windows-1252');
$trans['win_to_utf8'][$win[$i]] = $utf8;
$trans['from_utf8'][$utf8] = $win[$i];
}
for ($i = 0; $i < $winisolen; $i++) {
$utf8 = mb_convert_encoding($win_iso[$i], 'UTF-8', 'ISO-8859-1');
$trans['win_to_utf8'][$win_iso[$i]] = $utf8;
}
MCached::add(self::TRANSKEY, $trans, 86400);
}
self::$trans_table = $trans;
}