zl程序教程

您现在的位置是:首页 >  后端

当前栏目

PHP中实现汉字转区位码应用源码实例解析

实例PHP应用源码 实现 解析 汉字
2023-06-13 09:14:23 时间
复制代码代码如下:

<?php
global$PHP_SELF;
//echo$PHP_SELF;
$t1=$_POST["textfield1"];
$t2=$_POST["textfield2"];
$t3=$_POST["textfield3"];
$t4=$_POST["textfield4"];
//汉字--区位码
if($t1!=""){
$t2=sprintf("%02d%02d",ord($t1[0])-160,ord($t1[1])-160);
//echo$t2;
}
//区位码--汉字
if($t3!=""){
$t4=chr(substr($t3,0,2)+160).chr(substr($t3,2,2)+160);
//echo$t4;
}
?>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>无标题文档</title>
<styletype="text/css">
<!--
.STYLE1{font-size:18px}
-->
</style>
</head>
<body>
<tablewidth="528"height="146"border="1"
align="center"cellpadding="0"cellspacing="0">
<tr>
<tdwidth="524"height="50"><divalign="center"
class="STYLE1">汉字区位码查询系统</div></td>
</tr>
<tr>
<td><formid="form1"name="form1"method="post"action=
"<?=$PHP_SELF?>">
<label>输入汉字
<inputname="textfield1"type="text"value="<?=$t1?>"/>
</label>
<label>
<inputtype="submit"name="Submit"value="转换"/>
</label>
<label>
<inputname="textfield2"type="text"value="<?=$t2?>"/>
</label>
</form>
<br/>
<formid="form2"name="form2"method="post"action="<?=$PHP_SELF?>">
<label>输入区位码
<inputname="textfield3"type="text"value="<?=$t3?>"/>
</label>
<inputtype="submit"name="Submit2"value="转换"/>
<inputname="textfield4"type="text"value="<?=$t4?>"/>
</form>
</td>
</tr>
</table>
</body>
</html>