2006-09-05

GB2312 to UTF-8 for MySQL

$link = @mysql_pconnect("127.0.0.1","leeyc","xxxxxx") or die(throwError('unable to establish a connection'));

@mysql_select_db("chilier", $link) or die(throwError('unable to select database'));

mysql_query("set names utf8", $link); // 轉 GB2312 to UTF-8 需要先下這行指令


// 將 GB2312 碼轉為 UTF-8
function encodeString($s) {
$s = mb_convert_encoding($s, 'UTF-8', 'GB2312');
$s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
return $s;
}

沒有留言: