PHP編碼轉換減號(串連符)無法轉換問題

來源:互聯網
上載者:User

PHP編碼轉換減號(串連符)無法轉換問題技術

maybe yes 發表於2015-01-23 16:03

使 用 PHP 的 iconv 或 mb_convert_encoding 函數進行編碼轉換,比如將 gb2312 轉換為 utf-8 編碼,在出現某些特殊字元(減號,串連符)時,不能正常工作,可能會變成問號"?"或者"C"。嘗試了多種方法,依然不能很好的解決這個問題。如下代碼, 在聲明了 //IGNORE 後遇到串連符號"-"仍然會變成符號"?"。

  

按照 PHP 官網手冊中網友提供的解決方案進行嘗試,仍然不能解決問題,不知道是不是我本地 PHP 版本的問題。

解決方案一:
Please note that iconv('UTF-8', 'ASCII//TRANSLIT', ...) doesn't work properly when locale category LC_CTYPE is set to C or POSIX. You must choose another locale otherwise all non-ASCII characters will be replaced with question marks. This is at least true with glibc 2.5.
Example:
[翻譯]
請注意 iconv 在語言環境類別 LC_CTYPE 類別設定為 C 或者 POSIX 時不能正常的工作。你必須選擇另一個語言,否則所有的非 ASCLL 編碼將被替換成問號"?"。這個問題在 glibc 2.5 以下是真實的。
舉例如下:

  

解決方案二:
That will strip invalid characters from UTF-8 strings (so that you can insert it into a database, etc.). Instead of "none" you can also use the value 32 if you want it to insert spaces in place of the invalid characters.

  

閱(75)評(0)查看評論

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.