การแก้ปัญหา mb_internal_encoding error
ปัญหา mb_internal_encoding error เกิดจากการที่ server ไม่รองรับฟังก์ชั่นในกลุ่มนี้ครับ ซึ่งจะทำให้ฟังก์ชั่นที่ขึ้นต้นด้วย mb_ ไม่สามารถใช้งานได้ การแก้ไขให้ลองสอบถาม Server ครับ ว่าสามารถเปิดใช้งานฟังก์ชั่นในกลุ่มนี้ได้หรือไม่ แต่หากไม่สามารถเปิดใช้งานได้ สามารถแก้ไขได้โดยการใช้ฟังก์ชั่นนี้แทนครับ
[code=php] if (function_exists('mb_internal_encoding')) {
mb_internal_encoding('utf-8');
}
function substr_utf8($str, $from, $len) {
if (function_exists('mb_substr')) {
return mb_substr($str, $from, $len);
} else {
return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', '', $str);
}
}
function strlen_utf8($str) {
if (function_exists('mb_strlen')) {
return mb_strlen($str);
} else {
$i = 0;
$count = 0;
$len = strlen($str);
while ($i < $len) {
$chr = ord($str[$i]);
$count++;
$i++;
if ($i >= $len) {
break;
}
if ($chr & 0x80) {
$chr <<= 1;
while ($chr & 0x80) {
$i++;
$chr <<= 1;
}
}
}
return $count;
}
}
function cutstring($str, $len) {
return (strlen_utf8($str) <= $len || $len < 3) ? $str : substr_utf8($str, 0, $len - 2)."..";
}[/code]
ให้นำคำสั่งทั้งหมดด้านบน ไปแทนที่ substr_utf8, strlen_utf8 และ cutstring ใน bin/function.php ครับ และทำการ disabled ฟังก์ชั่น mb_internal_encoding ใน bin/config.php ครับ หรือจะเอาบรรทัดนี้ออกเลยก็ได้ครับ
[code=php] if (function_exists('mb_internal_encoding')) {
mb_internal_encoding('utf-8');
}
function substr_utf8($str, $from, $len) {
if (function_exists('mb_substr')) {
return mb_substr($str, $from, $len);
} else {
return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', '', $str);
}
}
function strlen_utf8($str) {
if (function_exists('mb_strlen')) {
return mb_strlen($str);
} else {
$i = 0;
$count = 0;
$len = strlen($str);
while ($i < $len) {
$chr = ord($str[$i]);
$count++;
$i++;
if ($i >= $len) {
break;
}
if ($chr & 0x80) {
$chr <<= 1;
while ($chr & 0x80) {
$i++;
$chr <<= 1;
}
}
}
return $count;
}
}
function cutstring($str, $len) {
return (strlen_utf8($str) <= $len || $len < 3) ? $str : substr_utf8($str, 0, $len - 2)."..";
}[/code]
ให้นำคำสั่งทั้งหมดด้านบน ไปแทนที่ substr_utf8, strlen_utf8 และ cutstring ใน bin/function.php ครับ และทำการ disabled ฟังก์ชั่น mb_internal_encoding ใน bin/config.php ครับ หรือจะเอาบรรทัดนี้ออกเลยก็ได้ครับ
18 พค. 2553 09:35 |
0 |
ดู 237 |
