Home >Backend Development >PHP Tutorial >How to use PHP to switch between Simplified and Traditional Chinese instantly_PHP Tutorial

How to use PHP to switch between Simplified and Traditional Chinese instantly_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:23:06867browse

Many websites have the function of switching between Simplified and Traditional Chinese in real time, but no one provides the method, so I also wrote a conversion program for the reference of those in need:
The table file used in the following program is a4chinese big5-gb.table, its copyright belongs to the author of a4chinese; the PHP code part can be modified freely, but it cannot be sold for profit..^^

<br>1.先取得big5-gb.table档,你可在文章下面的链接找到.<br>2.加入下列PHP程式码:<br><font color="#000080"><br>function <font color="#007a00">big52gb</font>(<font color="#900000">$Text</font>){<br><font color="#900000">$fp</font> = <font color="#007a00">fopen</font>("big5-gb.table", "r");<br><font color="#900000">$max</font>=<font color="#007a00">strlen</font>(<font color="#900000">$Text</font>)-1;<br><font color="#007a00">for</font>(<font color="#900000">$i</font>=0;<font color="#900000">$i</font>$max</font>;<font color="#900000">$i</font>++){<br><font color="#900000">$h</font>=<font color="#007a00">ord</font>(<font color="#900000">$Text</font>[<font color="#900000">$i</font>]);<br><font color="#007a00">if</font>(<font color="#900000">$h</font>>=160){<br><font color="#900000">$l</font>=<font color="#007a00">ord</font>(<font color="#900000">$Text</font>[<font color="#900000">$i</font>+1]);<br><font color="#007a00">if</font>(<font color="#900000">$h</font>==161 && <font color="#900000">$l</font>==64){<br><font color="#900000">$gb</font>="  ";<br>}<font color="#007a00">else</font>{<br><font color="#007a00">fseek</font>(<font color="#900000">$fp</font>,(<font color="#900000">$h</font>-160)*510+(<font color="#900000">$l</font>-1)*2); <br><font color="#900000">$gb</font>=<font color="#007a00">fread</font>(<font color="#900000">$fp</font>,2);      <br>}<br><font color="#900000">$Text</font>[<font color="#900000">$i</font>]=<font color="#900000">$gb</font>[0];<br><font color="#900000">$Text</font>[<font color="#900000">$i</font>+1]=<font color="#900000">$gb</font>[1];<br><font color="#900000">$i</font>++;<br>}<br>}<br><font color="#007a00">fclose</font>(<font color="#900000">$fp</font>);<br>return <font color="#900000">$Text</font>;<br>}<br><br>


3. Then you can use it

$a="Traditional to Simplified";
$a=big52gb($a ( This method, but because my method is still under testing, I don’t know whether it is stable or not, so I haven’t written it out yet)...^^


http://www.bkjia.com/PHPjc/446883.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/446883.htmlTechArticleMany websites have the function of instant switching between Simplified and Traditional Chinese, but no one provides the method, so I also wrote Here is a conversion program for those in need: The table file used in the following program is a...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn