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.