Example code for implementing Chinese character to location code in PHP

Source: Internet
Author: User

How to implement the Chinese character transcoding in PHP This problem has been plagued by most programmers, so the following source code example is believed to be of great help.

The following are the referenced contents:

<?php
Global $PHP _self;
echo $PHP _self;
$t 1=$_post[' textfield1 '];
$t 2=$_post[' textfield2 '];
$t 3=$_post[' textfield3 '];
$t 4=$_post[' Textfield4 '];

Chinese character--Location code
if ($t 1!= "") {
$t 2= sprintf ("%02d%02d", Ord ($t 1[0)) -160,ord ($t 1[1])-160);
echo $t 2;
}
Location code--Chinese characters
if ($t 3!= "") {
$t 4 = Chr (substr ($t 3,0,2) +160). Chr (substr ($t 3,2,2) +160);
Echo $t 4;
}
?>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<style type= "Text/css" >
<!--
. STYLE1 {font-size:18px}
-->
</style>

<body>
<table width= "528" height= "146" border= "1"
align= "center" cellpadding= "0" cellspacing= "0" >
<tr>
&LT;TD width= "524" height= "><div" "Center"
class= "STYLE1" > Chinese character Location Code query system </div></td>
</tr>
<tr>
<td><form id= "Form1" Name= "Form1" method= "POST" action=
"<?= $PHP _self?>" >
<label> Input Chinese characters
<input name= "Textfield1" type= "text" value= "<?= $t 1?>"/>
</label>
<label>
<input type= "Submit" name= "Submit" value= "Convert"/>
</label>
<label>
<input name= "Textfield2" type= "text" value= "<?= $t 2?>"/>
</label>
</form>
<br/>
<form id= "Form2" name= "Form2" method= "post" action= "<?= $PHP _self?>" >
<label> Input Location Code
<input name= "textfield3" type= "text" value= "<?= $t 3?>"/>
</label>
<input type= "Submit" Name= "Submit2" value= "Convert"/>
<input name= "Textfield4" type= "text" value= "<?= $t 4?>"/>
</form>
</td>
</tr>
</table>
</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.