이는 중국어 간체 및 번체로 패키지된 클래스입니다. 또 다른 두 개의 테이블 파일이 필요합니다. 1. http://www.jerry.com.tw/php/big5.map 2. //www.jerry.com.tw/php/gb.map 프로그램은 다음과 같습니다: CCharset.php3 < //============== = ===================================== // 프로그래머: 매직 제리 // // function Big5_Gb($str) => 문자열의 경우 big5를 GB로 // function Gb_Big5($str) => 문자열의 경우 GB를 Big5로 //===== = =============================================== class CCharset { var $gb_map="gb.map"; //다른 경로에 넣으려면 전체 경로를 추가하세요. var $big5_map="big5.map" //예를 들면= " /home/table/gb.map var $dep_char = 127; //---------------------------- ------------------------------------- 함수 cbig5_gb($str,$fd) { $c=ord(substr($str,0,1)) $x=ord(substr($str,1,1)) $address=(($c-160) )*510) ($x-1)*2; fseek($fd, $address) $hi=fgetc($fd) 🎜>return "$hi$lo"; } function cgb_big5($str,$fd) { $c=ord(substr($str,0,1)) $ x=ord(substr($str,1,1)); $address=(($c-160)*510) ($x-1)*2 fseek($fd, $address) ); $hi=fgetc($fd); $hi$lo" 반환 //-- ------------------------------------- ----------- function Big5_Gb($str) { $fd = fopen ($this->gb_map, "r") $str=str_replace(" charset=big5","charset=gb2312", $str); $outstr=""; for($i=0;$i $ch=ord(substr($str,$i,1)); if($ch > $this->dep_char) { $outstr.=$this->cbig5_gb(substr( $str,$i,2),$fd); $i ; } else { $outstr.=substr($str,$i,1) } fclose ($fd) $outstr 반환 } //------------ ---------------- 함수 Gb_Big5($str ) { $fd = fopen ($this->big5_map, "r") $str=str_replace("charset=gb2312","charset=big5", $str) $ outstr ="" for($i=0;$i$ch=ord(substr($str,$i,1)); > if($ch > $this->dep_char) { $outstr.=$this->cgb_big5(substr($str,$i,2),$fd) $i ; } else { $outstr.=substr($str,$i,1); } } fclose($fd) return $outstr; > } } ?> ============================== === ============================= 사용예:
/ / 디자이너 : Magic Jerry //====문자열 직접 변환 사용법======== include("CCharset.php3") $obj=new CCharset ; $big5="big5의 텍스트 문자열입니다." $tgb=$obj->Big5_Gb($big5) echo $tgb; 변환된 1GB 코드 문자열입니다 $tbig5=$obj->Gb_Big5($tgb) echo $tbig5; // 다시 반환됨: big5 //======= ============================ ?>
//직접 변환하는 경우 웹페이지 또는 파일 // 구문 http://your.domain.com.tw/this program.php3?http://웹페이지 URL 또는 트랜스코딩할 파일 // 예: QIMO 홈페이지 변환 // http://your.domain.com.tw/this program.php3?http://www.kimo.com.tw/index.shtml // 참고: 이 웹페이지에 다음 쓰기 사용자를 인증하는 등 쿠키를 사용하면 쫓겨나거나 잘못 로그인될 수 있습니다. // 왜 그럴까요? @_@ include("CCharset.php3"); $file=$QUERY_STRING; $fcontents = Join( '', file( "$file" ) ) $fc href=$file>", $fcontents); $code =new CCharset $gb=$code->Big5_Gb($fcontents); echo $gb;