Traditional conversion class_PHP

Source: Internet
Author: User
This is a traditional and traditional class with a class package. Two other table types are required: 1.www.jerry.com.twphpbig5.map2.www.jerry.com. twphpgb. map. The program is as follows: CCharset. php3? Programmer: MagicJerryfu: this is a class with a strong traditional programming class,
Two other table partitions are required:
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

// Programmer: Magic Jerry
//
// Function Big5_Gb ($ str) => big5 sans GB for string
// Function Gb_Big5 ($ str) => GB Gb_Big5 for string
// ================================================ ====================
Class CCharset {

Var $ gb_map = "gb. map"; // If you want to put it in another path, add 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;

}

}
?>

========================================================== ======================================
Example:
// Designer: Magic Jerry


// ====== How to use the text string ========
Include ("CCharset. php3 ");
$ Obj = new CCharset;
$ Big5 = "this is a big5 string ";
$ Tgb = $ obj-> Big5_Gb ($ big5 );
Echo $ tgb; // ==>$ tgb indicates a good gb limit string
$ Tbig5 = $ obj-> Gb_Big5 ($ tgb );
Echo $ tbig5; // returned by another response: big5
// ================================================
?>




// If you directly attempt to publish a website or website
// The routing method is http://your.domain.com.tw/? .php3? Http: // The url of the website to be accessed or the website
// Example: Zookeeper
// Http://your.domain.com.tw/? .php3? Http://www.kimo.com.tw/index.shtml
// Note: If the website has a cookie, such as a user, it may be kicked back ..
// Why? 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.