<?php
function gb2big5($str) {
$filepath='http://www.ugain.org/utilities/gb-big5.table';
$gb2big5_table=file_get_contents($filepath);
$max=strlen($str)-1;
for($i=0;$i<$max;$i++) {
$h=ord($str[$i]);
if($h>=160) {
$l=ord($str[$i+1]);
$gb=($h==161 && $l==64) ? " " : substr($gb2big5_table, ($h-160)*510+($l-1)*2, 2);
$str[$i]=$gb[0];
$str[$i+1]=$gb[1];
$i++;
}
}
return $str;
}//通过$_SESSION or $_GET来获得$charsetif($_GET['charset']=='big5'){
header('Content-Type: text/html; charset=big5');
ob_start('gb2big5');
}echo '测试123数据!';
ob_end_flush();
?>