Table of Contents
thinkphp 关于iis上面中文参数乱码问题
Home php教程 php手册 thinkphp 关于iis上面中文参数乱码问题

thinkphp 关于iis上面中文参数乱码问题

Jun 13, 2016 am 08:49 AM
Chinese Garbled characters parameter

thinkphp 关于iis上面中文参数乱码问题

第一种方法:

在使用 ?id="中文" 传递中文参数时,出现了乱码,这是经过了二次转码后的结果,其中,在 php 中,url 中是不可以直接传输中文的,对于这点,一直心存不满,没办法呀,谁让咱没一套解决方案呢,不知道别的语言是不是也出现这样的问题。

对于网上所说的在首页添加 header("content-type:text/html;charset=utf-8"); 这样的代码,以及把数据库页面等等设置成 utf8 的解决方案根本无效,始终传递过来的中文是乱码。

尽管站点PHP我都是用的统一的 utf8 编码,但始终传递过去是乱码,后来测试了几个浏览器,发现 360 可以传递过去,而 IE 不行,后来再使用 $msg = iconv('gbk','utf-8',$_GET["msg"]); 进行转换,测试几个浏览器后,大多还是显示乱码的问题。

最后总结了一点,对于 GET[] 过去的值,url 中不可以直接传输中文,如果必须要传输的话,用 urlencode() 方法来处理中文。对于 POST[]  不知道怎么样,暂时还没有做过实验。

看来也只有用 urlencode() 方法来处理中文了,在传递之前要先进行编码,传递过去之后再进行解决就可以了,那么利用如下两个函数:编码:".urlencode('中文').",解码:".urldecode('中文').",括号里的中文就是传递的字符了。

如下:传递页面先进行编码:td.php?id=".urlencode('中文').",接受页面进行解码即可:urldecode(id)."。

 

第二种方法:

如果gbk编码的页面生成的地址链接到utf-8的页面,gbk页面的中文是按照gbk的格式编码传送给下个页面,那么utf-8编码接收后肯定会出现乱码。

IIS的url重写模块,重写后的中文编码也是gbk,如果你的页面是utf-8编码,那么重写参数将会失效。像这些情况,我们就需要使用php内置的转码函数来处理编码问题了:

方案1:

$name = iconv("gbk","utf-8",$name);

方案2:

mb_convert_encoding($name, "utf-8", "gbk");

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set Chinese in Call of Duty: Warzone mobile game How to set Chinese in Call of Duty: Warzone mobile game Mar 22, 2024 am 08:41 AM

How to set Chinese in Call of Duty: Warzone mobile game

How to set Excel table to display Chinese? Excel switching Chinese operation tutorial How to set Excel table to display Chinese? Excel switching Chinese operation tutorial Mar 14, 2024 pm 03:28 PM

How to set Excel table to display Chinese? Excel switching Chinese operation tutorial

Will wwe2k24 have Chinese? Will wwe2k24 have Chinese? Mar 13, 2024 pm 04:40 PM

Will wwe2k24 have Chinese?

Setting up Chinese with VSCode: The Complete Guide Setting up Chinese with VSCode: The Complete Guide Mar 25, 2024 am 11:18 AM

Setting up Chinese with VSCode: The Complete Guide

How to set Quark browser to Chinese and how to set Chinese translation How to set Quark browser to Chinese and how to set Chinese translation Mar 12, 2024 pm 02:10 PM

How to set Quark browser to Chinese and how to set Chinese translation

Tips for solving Chinese garbled characters when writing txt files with PHP Tips for solving Chinese garbled characters when writing txt files with PHP Mar 27, 2024 pm 01:18 PM

Tips for solving Chinese garbled characters when writing txt files with PHP

How to change Google Chrome to Chinese mode? How to change Google Chrome to Chinese mode? Mar 13, 2024 pm 07:31 PM

How to change Google Chrome to Chinese mode?

How to solve the problem of garbled characters when importing Chinese data into Oracle? How to solve the problem of garbled characters when importing Chinese data into Oracle? Mar 10, 2024 am 09:54 AM

How to solve the problem of garbled characters when importing Chinese data into Oracle?

See all articles