define('PHP_INT_MAX', 2147483647); } # not available by default: if (!defined('PHP_INT_MIN')) { define('PHP_INT_MIN', (int) (-PHP_INT_MAX - 1)); } # override mbstring settings from php.ini # if (function_exists('mb_internal_encoding')) { @mb_internal_encoding('UTF-8'); } if (function_exists('mb_regex_encoding')) { @mb_regex_encoding('UTF-8'); } if (function_exists('mb_regex_set_options')) { @mb_regex_set_options('pr'); } # default: "pr" if (function_exists('mb_http_output')) { @mb_http_output('pass'); } if (function_exists('mb_language')) { @mb_language('uni'); } if (function_exists('mb_substitute_character')) { @mb_substitute_character(0xfffd); } # Unicode Replacement Character: # U+FFFD = 0xFFFD (utf16 hex) = 65533 (dec) = "\xEF\xBF\xBD" (utf8 hex) if (function_exists('mb_detect_order')) { @mb_detect_order('auto');
<?php mb_regex_set_options(''); $encs = array('EUC-JP', 'Shift_JIS', 'SJIS', 'UTF-8'); function test_ereg($test_enc, $pat, $str, $in_enc = 'EUC-JP') { mb_regex_encoding($test_enc); $pat = mb_convert_encoding($pat, $test_enc, $in_enc); $str = mb_convert_encoding($str, $test_enc, $in_enc); printf("(%d)%s\n", mb_ereg($pat, $str, $reg), is_array($reg) ? bin2hex(mb_convert_encoding(implode(' ', $reg), $in_enc, $test_enc)) : ''); } function do_tests($enc) { test_ereg($enc, 'abc ([a-z]+) ([a-z]+) ([a-z]+)$', "abc def ghi jkl"); $pat = '([a-z]+) ([ あ-か]+)([か-な]+) ([わ-ん]+)$'; test_ereg($enc, $pat, 'abc あおい かこな わゑん'); test_ereg($enc, $pat, 'mzxfp うおか きか をゐ'); } foreach ($encs as $enc) { do_tests($enc); } ?>
<?php var_dump(mb_http_input()); var_dump(mb_http_output()); var_dump(mb_language()); var_dump(mb_preferred_mime_name("sjis-win")); mb_regex_encoding("UTF-8"); var_dump(mb_regex_encoding()); var_dump(mb_regex_set_options()); var_dump(mb_regex_set_options("pz")); var_dump(mb_regex_set_options());
function MBYTE_checkEnabled($test = '', $enabled = true) { global $LANG_CHARSET; static $mb_enabled; if (!isset($mb_enabled)) { $mb_enabled = false; if (strcasecmp($LANG_CHARSET, 'utf-8') === 0) { if (empty($test)) { // Normal situation in live environment if (function_exists('mb_eregi_replace')) { $mb_enabled = mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); mb_regex_set_options('l'); } } elseif ($test === 'test') { // Just for tests, true if we want function to exist if ($enabled) { $mb_enabled = mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); mb_regex_set_options('l'); } } elseif ($test === 'test-reset') { // Just for tests, allow resetting $mb_enabled if (isset($mb_enabled)) { unset($mb_enabled); } } } } return $mb_enabled; }