PHP character transfer code: PHP character transcoding utf-8 to gb2312

Source: Internet
Author: User
Tags format array config explode interface php code query

Encountered PHP transcoding problem, almost did not torture me, no matter what I call the project in those functions, white Kung Fu, may be off the wrong, do not know, to find a lot of online, finally, finally, I found:
Iconv ("UTF-8", "gb2312", $username);
And here's the question I'm having:
I'm going to use the session username, on the config.php page, I can get, assign to variable
$username =$_session[' user_name '];
$fromuser = $username;
Then you have to upload this value to another page and then save it to the database, which is a hassle from config.php to newmessage.php page,
<input type= "hidden" name= "Fromuser" id= "Fromuser" "value=" <?php echo $fromuser;?> "/>"
According to the above, the value to newmessage.php page will appear garbled. To say, my whole system is utf-8 coded, and
Config.php is gb2312 (I also do not know why the config.php code directly to the Utf-8 directly appear garbled, anyway, it is
gb2312 or GBK), so you need to turn the code, the username config.php directly into the gb2312, the cost of Dickens
Finally found this crazy code, my writing is this:
$fromuser =iconv ("UTF-8", "gb2312", $username);
Tencent's IP Address API interface address: http://fw.qq.com/ipaddress
The data format returned is: var ipdata = new Array ("114.218.183.139″," "," Jiangsu province "," Suzhou ");
Use JS code to make a fetch:
View Source code Printing Help
1 <script language= "JavaScript"
Type= "Text/javascript"
Src= "Http://fw.qq.com/ipaddress" ></script>
2
3 <script>document.write ("Your IP is:" +ipdata[0]+ ", From:" +ipdata[2]);</script>
Methods to parse using PHP:
View Source code Printing Help
01 <?php
02 function
Getipplace () {
03 $ip =file_get_contents ("http://fw.qq.com/ipaddress");
04 $ip =str_replace (' "', '
', $IP);
05 $ip 2=explode ("(", $IP);
06 $a =substr ($ip 2[1],0,-2);
07 $b =explode (",", $a);
08 Return
$b;
09 }
10 $ip =getipplace ();
11 Print_r ($IP);
12 ?>
The output is an array after processing.
Other:
Sina's IP address query interface: HTTP://INT.DPOOL.SINA.COM.CN/IPLOOKUP/IPLOOKUP.PHP?FORMAT=JS
Sina Multi-Region test method: http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42
Sohu IP Address Query interface (default GBK): Http://pv.sohu.com/cityjson
Sohu IP Address Query interface (can be set code): Http://pv.sohu.com/cityjson?ie=utf-8
Sohu additional IP Address query interface: HTTP://TXT.GO.SOHU.COM/IP/SOIP
This article links http://www.cxybl.com/html/wlbc/Php/20130113/36055.html

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.