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

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?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>

相关文章

在WordPress中实现评论头像的自定义默认和延迟加载

自定义 WordPress 默认评论头像 对于没有设置Gravatra头像的评论者来说,WordPress会显示一个你在后台设置的默认头像,可以是神秘人、空白、默认的Gravatar 标...

php 字符串压缩方法比较示例

php 提供的字符串压缩方法有 1.gzcompress — Compress a string This function compress the given string usin...

strpos() 函数判断字符串中是否包含某字符串的方法

用php的strpos() 函数判断字符串中是否包含某字符串的方法 判断某字符串中是否包含某字符串的方法 if(strpos('www.idc-gz.com','idc-gz') !...

PHP MVC框架中类的自动加载机制实例分析

PHP MVC框架中类的自动加载机制实例分析

本文实例讲述了PHP MVC框架中类的自动加载机制。分享给大家供大家参考,具体如下: 原文 实现类的自动加载主要使用到了set_include_path和spl_autoload_re...

替换php字符串中的单引号为双引号的方法

实例如下: $param = "{'id':'12', 'name':'hi'}"; $new = preg_replace('/\"/', '"', $param); 以上这篇...