Class with simplified traditional conversion

Source: Internet
Author: User
Tags exit eval include join ord setcookie strlen
This is a class that is packed with classes,
Two other table files 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 Gb for string
function Gb_big5 ($str) => Gb Big5 for string
//=====================================================
Class Ccharset {

var $gb _map= "Gb.map"; If you want to put the other path, add the full path
var $big 5_map= "Big5.map"; For 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-&GT;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;

}

}
?>

===================================================================
Use examples:
?
Designer:magic Jerry.


= = = Direct conversion of the use of text strings ========
Include ("ccharset.php3");
$obj =new Ccharset;
$big 5 = "This is a Big5 text string";
$TGB = $obj-&GT;BIG5_GB ($big 5);
Echo $TGB; ===> $TGB for a converted GB code string.
$tbig 5= $obj->gb_big5 ($TGB);
echo $tbig 5; Has been turned back: Big5
//======================================
?>




?
If you switch directly to the Web or file,
The language http://your.domain.com.tw/this program. php3?http://URL or file to be encoded
Example: Convert qi Mo homepage
http://your.domain.com.tw/this program. php3?http://www.kimo.com.tw/index.shtml
Note: The following notation may be kicked back, login error, if you encounter a cookie on the Web page, such as user verification.
Why? Think about it ... @_@
Include ("ccharset.php3");
$file = $QUERY _string;
$fcontents = Join (' ", File (" $file "));
$fcontents =str_replace ("$code =new Ccharset;
$GB = $code-&GT;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 (the list ($key, $val) = each ($HTTP _cookie_vars)) {
echo "$key => $val <br>";
$url. = "&". $key. " = ". UrlEncode ($val);
}

$fcontents = Join (' ", File (" $url "));
$code =new Ccharset;
$fcontents = $code-&GT;BIG5_GB ($fcontents);
echo "converted $CHAR _GB";
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 details; font-size:9pt; letter-spacing:1pt; Text-decoration:none; COLOR:BALCK}
. frame_font {font-family: new details; font-size:9pt; letter-spacing:1pt; Text-decoration:none; Color:yellow}
. tablefont {font-family: new details; font-size:9pt; letter-spacing:1pt; Text-decoration:none; Color:. BodyColor {font-family: new details; 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= "Http://edu.cnzz.cn/NewsInfo/page_img/logo_2.gif";
Img4off = new Image ();
Img4off.src= "Http://edu.cnzz.cn/NewsInfo/http://edu.cnzz.cn/NewsInfo/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= ' > ';
echo "<tr>";
echo "<td width=200>";
echo "<table border=0 width=100% cellpadding=0 cellspacing=0 >";
echo "<tr><td>";
echo "<a href=index.php3";
echo "";
echo "";
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: Switch button 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= ' >";
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.