<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                **php 字符編碼轉換類,支持ANSI、Unicode、Unicode big endian、UTF-8、UTF-8+Bom 互相轉換。** **四種常見文本文件編碼方式** **ANSI編碼**: 無文件頭(文件編碼開頭標志性字節) ANSI編碼字母數字占一個字節,漢字占兩個字節 回車換行符,單字節, 十六進制表示為0d ?0a **UNICODE編碼:** 文件頭,十六進制表示為FF FE 每一個字符都用兩個字節編碼 回車換行符, 雙字節,十六進制表示為 000d ?000a **Unicode big endian編碼:** 文件頭十六進制表示為FE FF 后面編碼是把字符的高位放在前面,低位放在后面,正好和Unicode編碼顛倒 回車換行符,雙字節,十六進制表示為0d00 ?0a00 **UTF-8 編碼:** 文件頭,十六進制表示為EF BB BF UTF-8是Unicode的一種變長字符編碼,數字、字母、回車、換行都用一個字節表示,漢字占3個字節 回車換行符,單字節,十六進制表示為0d 0a **轉換原理:先把字符編碼轉為UTF-8,然后再從UTF-8轉換為對應的字符編碼。** **CharsetConv.class.php** ~~~ <?php /**字符編碼轉換類, ANSI、Unicode、Unicode big endian、UTF-8、UTF-8+Bom互相轉換 *Date: 2015-01-28 *Author: fdipzone *Ver: 1.0 * *Func: *public convert 轉換 *private convToUtf8 把編碼轉為UTF-8編碼 *private convFromUtf8 把UTF-8編碼轉換為輸出編碼 */ class CharsetConv{ // class start private $_in_charset = null; // 源編碼 private $_out_charset = null; // 輸出編碼 private $_allow_charset = array('utf-8', 'utf-8bom', 'ansi', 'unicode', 'unicodebe'); /**初始化 * @param String $in_charset 源編碼 * @param String $out_charset 輸出編碼 */ public function __construct($in_charset, $out_charset){ $in_charset = strtolower($in_charset); $out_charset = strtolower($out_charset); // 檢查源編碼 if(in_array($in_charset, $this->_allow_charset)){ $this->_in_charset = $in_charset; } // 檢查輸出編碼 if(in_array($out_charset, $this->_allow_charset)){ $this->_out_charset = $out_charset; } } /**轉換 * @param String $str 要轉換的字符串 * @return String 轉換后的字符串 */ public function convert($str){ $str = $this->convToUtf8($str); // 先轉為utf8 $str = $this->convFromUtf8($str); // 從utf8轉為對應的編碼 return $str; } /**把編碼轉為UTF-8編碼 * @param String $str * @return String */ private function convToUtf8($str){ if($this->_in_charset=='utf-8'){ // 編碼已經是utf-8,不用轉 return $str; } switch($this->_in_charset){ case 'utf-8bom': $str = substr($str, 3); break; case 'ansi': $str = iconv('GBK', 'UTF-8//IGNORE', $str); break; case 'unicode': $str = iconv('UTF-16le', 'UTF-8//IGNORE', substr($str, 2)); break; case 'unicodebe': $str = iconv('UTF-16be', 'UTF-8//IGNORE', substr($str, 2)); break; default: break; } return $str; } /**把UTF-8編碼轉換為輸出編碼 * @param String $str * @return String */ private function convFromUtf8($str){ if($this->_out_charset=='utf-8'){ // 輸出編碼已經是utf-8,不用轉 return $str; } switch($this->_out_charset){ case 'utf-8bom': $str = "\xef\xbb\xbf".$str; break; case 'ansi': $str = iconv('UTF-8', 'GBK//IGNORE', $str); break; case 'unicode': $str = "\xff\xfe".iconv('UTF-8', 'UTF-16le//IGNORE', $str); break; case 'unicodebe': $str = "\xfe\xff".iconv('UTF-8', 'UTF-16be//IGNORE', $str); break; default: break; } return $str; } } // class end ?> ~~~ **demo:**unicode big endian 轉為 utf-8+bom ~~~ <?php require "CharsetConv.class.php"; $str = file_get_contents('source/unicodebe.txt'); $obj = new CharsetConv('unicodebe', 'utf-8bom'); $response = $obj->convert($str); file_put_contents('response/utf-8bom.txt', $response, true); ?> ~~~ **源碼下載地址:[點擊查看](http://download.csdn.net/detail/fdipzone/8411291)**
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看