關於轉碼有關問題

來源:互聯網
上載者:User
關於轉碼問題
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)
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.