php中big5轉(zhuǎn)utf8亂碼的解決辦法:首先生成tab文件,并生成時要保證tab文件不存在;然后將指定頁面轉(zhuǎn)碼測試;接著打印出文字庫;最后big5轉(zhuǎn)【utf-8】即可。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名注冊、網(wǎng)頁空間、營銷軟件、網(wǎng)站建設(shè)、南昌網(wǎng)站維護、網(wǎng)站推廣。
php中big5轉(zhuǎn)utf8亂碼的解決辦法:
第一步:生成tab文件,生成時要保證tab文件不存在才可以
writebig5UnicodeFile();
第二步:指定頁面轉(zhuǎn)碼測試
testCode();
第三步:打印出文字庫
printfCode();
$unicode) { $h = floor($big5/256); $l = $big5%256; $index = ($h-135)*256*3+$l*3; if($index<$min) { $min = $index; } if($max<$index) { $max = $index; } if($unicode>$max_unicode) { $max_unicode = $unicode; } $h_1 = floor($unicode/65536); $h_2 = floor($unicode/256); $h_3 = $unicode%256; $big5_unicod_content[$index] = chr($h_1).chr($h_2).chr($h_3); } for($i=0;$i<=$max;$i=$i+3) { if(!isset($big5_unicod_content[$i])) { $big5_unicod_content[$i] = chr(0).chr(0).chr(0); } } for($i=0;$i<=$max;$i=$i+3) { if(strlen($big5_unicod_content[$i]) == 3) { putContent($big5_unicod_content[$i]); }else{ die('error'); } } } //測試編輯結(jié)果 function testCode() { $content = file_get_contents( './temlate_2.html'); echo b2u($content); } //打印出編碼庫文字 function printfCode() { $fp = fopen( './big5-unicode-new.tab', 'r' ); $len = filesize('./big5-unicode-new.tab'); $x = 0; $outstr = array(); // fseek( $fp, 21000 - 900 + 42*3); for($i=$x=0;$i<$len;$i=$i+3) { $uni = fread( $fp, 3 ); $codenum = ord($uni[0])*65536 + ord($uni[1])*256 + ord($uni[2]); if($codenum == 0) { $outstr[$x++] = ' '; }elseif( $codenum < 0x80 ) { $outstr[$x++] = chr($codenum); }elseif($codenum < 0x800) { $outstr[$x++] = chr( 192 + $codenum / 64 ); $outstr[$x++] = chr( 128 + $codenum % 64 ); }elseif($codenum < 0x10000){ $outstr[$x++] = chr( 224 + floor($codenum / 4096 )); $codenum = $codenum%4096; $outstr[$x++] = chr( 128 + floor($codenum / 64 )); $outstr[$x++] = chr( 128 + ($codenum % 64) ); }else{ $outstr[$x++] = chr( 240 + floor($codenum / 262144 )); $codenum = $codenum%262144; $outstr[$x++] = chr( 128 + floor($codenum / 4096 )); $codenum = $codenum%4096; $outstr[$x++] = chr( 128 + ($codenum / 64) ); $outstr[$x++] = chr( 128 + ($codenum % 64) ); } } echo join( '', $outstr); } //big5 轉(zhuǎn) utf-8 function b2u( $instr ) { $fp = fopen( './big5-unicode-new.tab', 'r' ); $len = strlen($instr); $outstr = ''; for( $i = $x = 0 ; $i < $len ; $i++ ) { $h = ord($instr[$i]); if( $h >= 135 ) { $l = ord($instr[$i+1]); fseek( $fp, ($h-135)*256*3+$l*3 ); $uni = fread( $fp, 3 ); $codenum = ord($uni[0])*65536 + ord($uni[1])*256 + ord($uni[2]); if($codenum == 0) { $outstr[$x++] = ' '; }elseif( $codenum < 0x80 ) { $outstr[$x++] = chr($codenum); }elseif($codenum < 0x800) { $outstr[$x++] = chr( 192 + $codenum / 64 ); $outstr[$x++] = chr( 128 + $codenum % 64 ); }elseif($codenum < 0x10000){ $outstr[$x++] = chr( 224 + floor($codenum / 4096 )); $codenum = $codenum%4096; $outstr[$x++] = chr( 128 + floor($codenum / 64 )); $outstr[$x++] = chr( 128 + ($codenum % 64) ); }else{ $outstr[$x++] = chr( 240 + floor($codenum / 262144 )); $codenum = $codenum%262144; $outstr[$x++] = chr( 128 + floor($codenum / 4096 )); $codenum = $codenum%4096; $outstr[$x++] = chr( 128 + ($codenum / 64) ); $outstr[$x++] = chr( 128 + ($codenum % 64) ); } $i++; } else $outstr[$x++] = $instr[$i]; } fclose($fp); if( $instr != '' ) return join( '', $outstr); }