>开发语言>PHP > PHP中实现汉字转区位码应用源码实例解析

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

2019年04月28日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下: <?php global $php_self; //echo $php_self; $t1=$_post['textfield1']; $t2=
复制代码 代码如下:

<?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;
}
?>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {font-size: 18px}
-->
</style>
</head>
<body>
<table width="528" height="146" border="1"
align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="524" height="50"><div align="center"
class="style1">汉字区位码查询系统</div></td>
</tr>
<tr>
<td><form id="form1" name="form1" method="post" action=
"<?=$php_self ?>">
<label>输入汉字
<input name="textfield1" type="text" value="<?=$t1?>" />
</label>
<label>
<input type="submit" name="submit" value=" 转 换 " />
</label>
<label>
<input name="textfield2" type="text" value="<?=$t2?>" />
</label>
</form>
<br />
<form id="form2" name="form2" method="post" action="<?=$php_self ?>">
<label>输入区位码
<input name="textfield3" type="text" value="<?=$t3?>" />
</label>
<input type="submit" name="submit2" value=" 转 换 " />
<input name="textfield4" type="text" value="<?=$t4?>" />
</form>
</td>
</tr>
</table>
</body>
</html>

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网