? Traditional conversion class

Source: Internet
Author: User
? Is it a class package? Okay? Complex ??? Q class. What else do I need ??? Table? N: 1. why? /// Program? T: MagicJerry // fu? Is it a class package? Okay? Complex ??? Q class,
In addition ??? Table? N:
1. http://www.jerry.com.tw/php/big5.map
2. http://www.jerry.com.tw/php/gb.map
The program is as follows: CCharset. php3

// Program? T: Magic Jerry
//
// Function Big5_Gb ($ str) => big5? GB for string
// Function Gb_Big5 ($ str) => GB? Big5 for string
// ================================================ ====================
Class CCharset {

Var $ gb_map = "gb. map"; // If you want to put it in? E path ?? What is the complete path?
Var $ big5_map = "big5.map"; // example = "/home/table/gb. map

Var $ dep_char= 127;


//-----------------------------------------------------------------
Function 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 );
$ Lo = 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 );
$ Lo = fgetc ($ fd );
Return "$ 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 );
Return $ outstr;
}
//-----------------------------------------------------------------
Function 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;

}

}
?>

========================================================== ======================================
Use? Example:
// Designer: Magic Jerry


// ==== Direct ?? Q: How to use text strings ========
Include ("CCharset. php3 ");
$ Obj = new CCharset;
$ Big5 = "? Yes ?? Big5 text string ";
$ Tgb = $ obj-> Big5_Gb ($ big5 );
Echo $ tgb; // ==>$ tgb? Mongod? Q good gb? String
$ Tbig5 = $ obj-> Gb_Big5 ($ tgb );
Echo $ tbig5; // What is it again? ? Why? Big5
// ================================================
?>




// If direct ?? Q ?? Or? N case
//? Legal http://your.domain.com.tw /??? Program. php3? Http: // Yes ?? ?? Url or? N case
// Example :?? Q Qimo?
// Http://your.domain.com.tw /??? Program. php3? Http://www.kimo.com.tw/index.shtml
// Note: the following ?? Method ??? Cookie is used, such ?? User, possibly ?? Warehouse? Login ??..
//? Acer treasure N? Think about it ...@_@
Include ("CCharset. php3 ");
$ File = $ QUERY_STRING;
$ Fcontents = join ('', file (" $ file "));
$ Fcontents = str_replace (""," ", $ Fcontents );
$ Code = new CCharset;
$ Gb = $ code-> Big5_Gb ($ fcontents );
Echo $ gb;
?>



? Example:


If ($ func = "charset "){
Setcookie ("CHAR_GB", $ GB, time () 31536000 );
$ T = time ();
$ Url = "http: //". $ HTTP_HOST. $ PHP_SELF ."? ". $ QUERY_STRING;
$ Url = str_replace ("? Func = charset & GB = 1 "," ", $ url );
$ Url = str_replace ("? Func = charset & GB = 0 "," ", $ url );
$ Url = str_replace ("& func = charset & GB = 1", "", $ url );
$ Url = str_replace ("& func = charset & GB = 0", "", $ url );
// Echo $ url;
// Echo "SET to Charset = $ CHAR_GB ";
$ T = time ();
Echo"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.