PHP中實現(xiàn)漢字轉區(qū)位碼應用源碼實例解析
更新時間:2010年06月14日 01:26:18 作者:
PHP里如何實現(xiàn)漢字轉區(qū)位碼這個問題一直困擾這大多程序員,那么下面這個源碼實例相信能給大家?guī)砗艽蟮膸椭?/div>
<?php
global $PHP_SELF;
//echo $PHP_SELF;
$t1=$_POST['textfield1'];
$t2=$_POST['textfield2'];
$t3=$_POST['textfield3'];
$t4=$_POST['textfield4'];
// 漢字--區(qū)位碼
if($t1!=""){
$t2= sprintf("%02d%02d",ord($t1[0])-160,ord($t1[1])-160);
//echo $t2;
}
// 區(qū)位碼--漢字
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">漢字區(qū)位碼查詢系統(tǒng)</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>輸入?yún)^(qū)位碼
<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>
復制代碼 代碼如下:
<?php
global $PHP_SELF;
//echo $PHP_SELF;
$t1=$_POST['textfield1'];
$t2=$_POST['textfield2'];
$t3=$_POST['textfield3'];
$t4=$_POST['textfield4'];
// 漢字--區(qū)位碼
if($t1!=""){
$t2= sprintf("%02d%02d",ord($t1[0])-160,ord($t1[1])-160);
//echo $t2;
}
// 區(qū)位碼--漢字
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">漢字區(qū)位碼查詢系統(tǒng)</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>輸入?yún)^(qū)位碼
<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>
您可能感興趣的文章:
相關文章
淺析PHP原理之變量分離/引用(Variables Separation)
以下小編就為大家介紹一下PHP中變量分離和引用的概念。需要的朋友可以過來參考下2013-08-08淺析php靜態(tài)方法與非靜態(tài)方法的用法區(qū)別
下面小編就為大家?guī)硪黄獪\析php靜態(tài)方法與非靜態(tài)方法的用法區(qū)別。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05PHP圖像處理之使用imagecolorallocate()函數(shù)設置顏色例子
這篇文章主要介紹了PHP圖像處理之使用imagecolorallocate()函數(shù)設置顏色例子,本文給出了十進制和十六進制2種設置顏色的方法,需要的朋友可以參考下2014-11-11