Convert Simplified Chinese to Traditional Chinese PHP functions

Source: Internet
Author: User
Tags chr include ord strlen strtok
function | chinese | Convert Thank you Netizen Keyes provide the Delphi source code of the transplant. The method is called $txt=gbtobig5 ($txt).


(note: In source code include "data_gb.php"; This file is an array, in Http://caocao.oso.com.cn/data_gb.zip, please edit the download to Oso, do a link, because this file I will be deleted in a few days. )





;?


/***********************************************************************


written by Caocao


caocao@eastday.com


http://caocao.oso.com.cn





with the help of Keyes


Keyes2000@263.net


Http://my-wjl.scu.edu.cn/~Keyes


***********************************************************************/


function Isgb ($code)


{


if (strlen ($code) >=2)


{


$code =strtok ($code, "");


if (ord ($code [0]) < 161) | | (Ord ($code [0]) >= 247))


{


return (0);


}


Else


{


if ((Ord ($code [1]) <= 161) | | (Ord ($code [1]) >= 254))


{


return (0);


}


Else


{


return (1);


}


}


}


Else


{


return (1);


}


}





function Gboffset ($code)


{


if (strlen ($code) >= 2)


{


$code =strtok ($code, "");


return ((Ord ($code [0])-161) * (Ord ($code [1])-161);


}


Else


{


return (-1);


}


}





function wordtostring ($code)


{


return (Chr hexdec (substr ($code, 0,2)). Chr (Hexdec (substr ($code, 2,2)));


}





function Gbtobig5 ($code)


{


Include "data_gb.php";


$output = "";


$length =strlen ($code);


$code =strtok ($code, "");


$idx = 0;


while ($idx < $length)


{


$tmpStr = $code [$idx]. $code [$idx +1];





if (ISGB ($TMPSTR))


{


$offset =gboffset ($TMPSTR);


if ($offset >= 0) | | ($offset <= 8177))


{


$output. =wordtostring ($gborder [$offset]);


$idx + +;


}


Else


{


$output. = $code [$idx];


}


}


Else


{


$output. = $code [$idx];


}


$idx + +;


}


return ($output);


};


?>














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.