A-A+
php汉字如何转区位码
php汉字转区位码的方法:首先创建一个PHP示例文件;然后通过“sprintf("%02d%02d",ord($t1[0])-160,ord($t1[1])-160);”方法实现汉字转区位码即可。
PHP中实现汉字转区位码应用源码实例解析
PHP里如何实现汉字转区位码这个问题一直困扰这大多程序员,那么下面这个源码实例相信能给大家带来很大的帮助。
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<!--?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; } ?--> <meta http-equiv= "Content-Type" content= "text/html; charset=gb2312" > <title>无标题文档</title> <style type= "text/css" > <!-- .STYLE1 {font-size: 18px} --> </style> <table width= "528" height= "146" border= "1" align= "center" cellpadding= "0" cellspacing= "0" > <tbody><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> </tbody></table> |