Simplified traditional conversion class

Source: Internet
Author: User

This is a class that has been written in the class package,
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 <strlen ($ str); $ 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 <strlen ($ str); $ 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 ("$ 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"
<Script language = javascript>
Document. location = '$ url'
</Script>
";

Exit;
}
// Phpinfo ();
If ($ CHAR_GB = 1 &&! $ Istran ){
Include ("CCharset. php3 ");
If (strlen ($ QUERY_STRING) $ url = "http: //". $ HTTP_HOST. $ PHP_SELF ."? ". $ QUERY_STRING." & istran = 1 ";
Else $ url = "http: //". $ HTTP_HOST. $ PHP_SELF ."? Istran = 1 ";

While (list ($ key, $ val) = each ($ HTTP_COOKIE_VARS )){
// Echo "$ key => $ val <br> ";
$ Url. = "&". $ key. "=". urlencode ($ val );
}

$ Fcontents = join ('', file (" $ url "));
$ Code = new CCharset;
$ Fcontents = $ code-> Big5_Gb ($ fcontents );
// Echo "$ CHAR_GB occupied ";
Echo $ fcontents;
Exit;

}
//} Else setcookie ("CHAR_GB", 0, time () + 31536000 );
Echo"
<Meta http-equiv = 'content-type' Content = 'text/html; charset = big5'>
<Style type = "text/css">
// <! --
. Menufont {FONT-FAMILY: New simhei; FONT-SIZE: 9pt; LETTER-SPACING: 1pt; TEXT-DECORATION: none; color: balck}
. Frame_font {FONT-FAMILY: New plaintext; FONT-SIZE: 9pt; LETTER-SPACING: 1pt; TEXT-DECORATION: none; color: yellow}
. Tablefont {FONT-FAMILY: New plaintext; FONT-SIZE: 9pt; LETTER-SPACING: 1pt; TEXT-DECORATION: none; color :. bodycolor {FONT-FAMILY: New plaintext; FONT-SIZE: 9pt; LETTER-SPACING: 1pt; TEXT-DECORATION: none; color :. num {FONT-FAMILY: Arial; font-weight: bold; font-style: normal; FONT-SIZE: 8pt; LETTER-SPACING: 1pt; TEXT-DECORATION: none; color: a {color: green; TEXT-DECORATION: none}
A: hover {color: red ;}
// -->
</Style>
";

Echo
"<SCRIPT language = JavaScript>
<! --
If (document. images ){

Img4on = new Image ();
Img4on. src = "page_img/logo_2.gif ";
Img4off = new Image ();
Img4off. src = "page_img/logo.gif ";
}
Function imgOn (imgName ){
If (document. images ){
Document [imgName]. src = eval (imgName + "on. src ");}}

Function imgOff (imgName ){
If (document. images ){
Document [imgName]. src = eval (imgName + "off. src ");}}
// -->
</SCRIPT> ";

Echo "<body leftMargin = 0 rightMargin = 0 topMargin = 0 marginwidth = '0' marginheight = '0'> ";
Include ("hows. php3 ");
Echo "<TABLE border = 0 width = 100% cellPadding = 0 cellSpacing = 0> ";
Echo "<TR> ";
Echo "<TD bgcolor ='
Echo "<a href = http://www.jerry.com.tw/> ";
Echo " ";
Echo "</a> ";

Echo "</TD> ";
Echo "<TD bgcolor = 'echo" <TABLE border = 0 width = 100% cellPadding = 0 cellSpacing = 0 class = 'frame _ font'> ";
Echo "<tr> ";
Echo "& lt; td width = 200 & gt ";
Echo "<TABLE border = 0 width = 100% cellPadding = 0 cellSpacing = 0> ";
Echo "<tr> <td> ";
Echo "<a href = index. php3 ";
Echo "onmouseout =" imgOff ('img4 ')"";
Echo "onmouseover =" imgOn ('img4 ')"";
Echo "> ";
Echo " ";
Echo "</a> ";
Echo "</td> </tr> ";
Echo "<tr> <td align = 'center'> ";
Include ("hows_2.php3 ");
Echo "</td> </tr> ";
Echo "</table> ";
Echo "</td> ";
Echo "<td valign = bottom> ";
Echo "<TABLE border = 0 width = 90% cellPadding = 0 cellSpacing = 0 class = 'frame _ font'> ";
$ Tb = "width = 20% height = 18 align = left ";
$ Fnt = "& sz = 18 & cr = 231 & cg = 255 & cb = 123 & br = 102 & bg = 153 & bb = 153 & sh = 1 ";
Echo "<tr> ";
Echo "<td width = 20% $ tb> ";
Echo "<a href = nbbs. php3? Proc = area & aid = 3> ";
Echo " ";
Echo "</a> ";
Echo "</td> ";
Echo "<td $ tb> ";
Echo "<a href = nbbs. php3? Proc = area & aid = 9> ";
Echo " ";
Echo "</a> ";
Echo "</td> ";
Echo "<td $ tb> ";
Echo "<a href = nbbs. php3? Proc = area & aid = 4> ";
Echo " ";
Echo "</a> ";
Echo "</td> ";
Echo "<td $ tb> ";
Echo "<a href = nbbs. php3? Proc = area & aid = 10> ";
Echo " ";
Echo "</a> ";
Echo "</td> ";
Echo "<td $ tb> ";
If (strlen ($ QUERY_STRING) $ aurl = "http: //". $ HTTP_HOST. $ PHP_SELF ."? ". $ QUERY_STRING;
Else $ aurl = "http: //". $ HTTP_HOST. $ PHP_SELF;
$ Aurl = str_replace ("? CHAR_GB = 1 "," ", $ aurl );
$ Aurl = str_replace ("? CHAR_GB = 0 "," ", $ aurl );
$ Aurl = str_replace ("& CHAR_GB = 1", "", $ aurl );
$ Aurl = str_replace ("& CHAR_GB = 0", "", $ aurl );
If (isset ($ CHAR_GB) & $ CHAR_GB = 1 ){
If (strlen ($ QUERY_STRING ))
Echo "<a href = $ aurl & func = charset & GB = 0> ";
Else echo "<a href = $ aurl? Func = charset & GB = 0> ";
Echo " ";
Echo "</a> ";
} Else {
If (strlen ($ QUERY_STRING ))
Echo "<a href = $ aurl & func = charset & GB = 1> ";
Else echo "<a href = $ aurl? Func = charset & GB = 1> ";
Echo " ";
Echo "</a> ";
}
Echo "</td> ";
Echo "</tr> ";
Echo "<tr> ";
Echo "<td $ tb> ";
Echo "<a href = php_url.php3> ";
Echo " ";
Echo "</a> ";;
Echo "</td> ";
Echo "<td $ tb> ";
Echo "<a href = php_news.php3> ";
Echo " ";
Echo "</a> ";
Echo "</td> ";
Echo "<td $ tb> ";
Echo "<a href = singin. php3> ";
Echo " ";
Echo "</a> ";
Echo "</td> ";

Echo "<td $ tb> ";
Echo "<a href = index. php3> ";
Echo " ";
Echo "</a> ";
Echo "</td> ";
Echo "<td $ tb> ";
Echo "NOTE: please do not press ";
Echo "</td> ";
Echo "</tr> ";
Echo "</table> ";
Echo "</td> ";

Echo "</tr> ";
Echo "</table> ";
Echo "</TD> ";

Echo "</TR> ";
Echo "<TR> ";
Echo "<TD valign = top height = '25'> ";
Echo " ";
Echo "</TD> ";
Echo "</TR> ";
Echo "<TR> ";
Echo "<TD> ";

?>

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.