How to implement the Chinese character transcoding in PHP This problem has been plagued by most programmers, so the following source code example is believed to be of great help.
| The following are the referenced contents: <?php Global $PHP _self; echo $PHP _self; $t 1=$_post[' textfield1 ']; $t 2=$_post[' textfield2 ']; $t 3=$_post[' textfield3 ']; $t 4=$_post[' Textfield4 '];
Chinese character--Location code if ($t 1!= "") { $t 2= sprintf ("%02d%02d", Ord ($t 1[0)) -160,ord ($t 1[1])-160); echo $t 2; } Location code--Chinese characters if ($t 3!= "") { $t 4 = Chr (substr ($t 3,0,2) +160). Chr (substr ($t 3,2,2) +160); Echo $t 4; } ?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <title> Untitled Document </title> <style type= "Text/css" > <!-- . STYLE1 {font-size:18px} --> </style>
<body> <table width= "528" height= "146" border= "1" align= "center" cellpadding= "0" cellspacing= "0" > <tr> <TD width= "524" height= "><div" "Center" class= "STYLE1" > Chinese character Location Code query system </div></td> </tr> <tr> <td><form id= "Form1" Name= "Form1" method= "POST" action= "<?= $PHP _self?>" > <label> Input Chinese characters <input name= "Textfield1" type= "text" value= "<?= $t 1?>"/> </label> <label> <input type= "Submit" name= "Submit" value= "Convert"/> </label> <label> <input name= "Textfield2" type= "text" value= "<?= $t 2?>"/> </label> </form> <br/> <form id= "Form2" name= "Form2" method= "post" action= "<?= $PHP _self?>" > <label> Input Location Code <input name= "textfield3" type= "text" value= "<?= $t 3?>"/> </label> <input type= "Submit" Name= "Submit2" value= "Convert"/> <input name= "Textfield4" type= "text" value= "<?= $t 4?>"/> </form> </td> </tr> </table> </body> |