Classified post simple and traditional conversion class

Source: Internet
Author: User
Tags ord
This is a class that is packaged in a simple,
In addition, two 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 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) * *;
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) * *;
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;
}
}
?>
===================================================================
Examples of Use:
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->BIG5_GB ($big 5);
Echo $TGB; ===> $TGB for the conversion of a good GB code string
$tbig 5= $obj->gb_big5 ($TGB);
echo $tbig 5; And was turned back: Big5
//======================================
?>
If you switch directly to a Web page or file,
The language method http://your.domain.com.tw/this program. php3?http://the URL or file of the Web page to be encoded
Example: conversion to the first page of Qi mo
http://your.domain.com.tw/this program. php3?http://www.kimo.com.tw/index.shtml
Note: The following writing method may be kicked back and login wrong if it encounters a cookie that has been used in this web page, for example, to verify the user.
Why? Think about it ... @_@
Include ("ccharset.php3");
$file = $QUERY _string;
$fcontents = Join (', File ("$file"));
$FC href= $file > ", $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 "

";
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 and $val
";
$url. = "&". $key. " = ". UrlEncode ($val);
}
$fcontents = Join (', File ("$url"));
$code =new Ccharset;
$fc
echo "$CHAR _GB";
Echo $fcontents;
Exit
}
} else Setcookie ("CHAR_GB", 0,time () + 31536000);
echo "
";
Include ("hows.php3");
echo "






";echo " "; echo " "; echo " ";echo " ";echo " ";echo " ";echo "
";
echo "


"; echo " "; echo " "; echo "
";
echo "echo" ";
echo "";
echo ">";
echo "";
echo "";
echo "
";
Include ("hows_2.php3");
echo "
";
echo "
";
echo "
















";$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 " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " ";echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " ";echo "
";
echo "";
echo "";
echo "";
echo "
";
echo "";
echo "";
echo "";
echo "
";
echo "";
echo "";
echo "";
echo "
";
echo "";
echo "";
echo "";
echo "
";
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 "";
else echo "";
echo "";
echo "";
} else {
if (strlen ($QUERY _string))
echo "";
else echo "";
echo "";
echo "";
}
echo "
";
echo "";
echo "";
echo "";;
echo "
";
echo "";
echo "";
echo "";
echo "
";
echo "";
echo "";
echo "";
echo "
";
echo "";
echo "";
echo "";
echo "
";
echo "NOTE: Please do not continue to press the button";
echo "
";
echo "
";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
?>

The above describes the classified post simple and traditional conversion class, including the classified post aspect of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.