關於轉碼問題
import 503-9256962-4382268 Failure -1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '054-246-0787','JPS0001' ,'0243-BK', 'iphone 4 用臂帶 (黑色)', '1', '鷲??' at line 1
我進行了轉碼也報以上錯誤,我的轉碼函數:
$recipient_name=mb_convert_encoding(addslashes($u[16]), 'UTF-8','UTF-8,sjis-win,eucjp-win');
echo base64_encode($u[16])結果:mGiRg4xc
我輸出轉碼後的結果是對的:"鷲巣圭",但是不知道寫入資料庫就會報錯,我發現只有包含"圭"的都會寫入資料庫失敗。
請問有什麼辦法解決這個問題??
分享到:
------解決方案--------------------
$s = base64_decode('mGiRg4xc');
echo '字元集 ', mb_detect_encoding($s, 'UTF-8,sjis-win,eucjp-win'), '
';
echo '16進位內碼 ', bin2hex($s), '
';
echo 'utf-8 ', $t = mb_convert_encoding($s, 'utf-8', 'UTF-8,sjis-win,eucjp-win'), '
';
echo '16進位內碼 ', bin2hex($t);
字元集 JIS-win
16進位內碼 986891838c5c 這個 5c 是 \ 的16進位內碼
utf-8 鷲巣圭
16進位內碼 e9b7b2e5b7a3e59cad
所以你需要
$recipient_name=mb_convert_encoding($u[16], 'UTF-8','UTF-8,sjis-win,eucjp-win');
而不是
$recipient_name=mb_convert_encoding(addslashes($u[16]), 'UTF-8','UTF-8,sjis-win,eucjp-win');
即不能用 addslashes 做轉義處理
轉義 ' 需要用 str_replace("'", "\'", $s)