2009年3月21日

[php]將Unicode轉換為Big5,缺字以&#xxxxx編碼顯示

將UTF-16 or UTF-8 轉換為Big5,無法轉換的字以 &#xxxxx 的編碼代替(參考網路文章測試後再修改之~):
* php 需安裝 mbstring模組: php_mbstring.dll

//轉換編碼時無法轉換的字元,設定應用何種方式顯示(預設: ?、none: 無、long: U+xxx)
mb_substitute_character("long");
$file_cont=convertUnicodeNotation(mb_convert_encoding($file_cont, 'BIG5', 'UCS-2LE'));
//echo convertUnicodeNotation(mb_convert_encoding($data, 'BIG-5', 'UTF-8'));

//將 U+79C3 之類的編碼,轉換為&#xxxxx => '&#'.intval('79C3',16)
function convertUnicodeNotation($str) {
if (eregi('U\+([0-9A-F]{4})',$str,$regs))
{ return convertUnicodeNotation(str_replace($regs[0], '&#'.intval($regs[1],16).';', $str));
}
return $str;
}

2009年3月10日

[MySQL]Can't open file: 'xxx.MYI'. (errno: 144)

Can't open file: 'xxx.MYI'. (errno: 144)
OS下命令: myisamchk -f (table所在路徑/)xxx.MYI 即可修復