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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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

Call of Duty Warzone is a newly launched mobile game. Many players are very curious about how to set the language of this game to Chinese. In fact, it is very simple. Players only need to download the Chinese language pack, and then You can modify it after using it. The detailed content can be learned in this Chinese setting method introduction. Let us take a look together. How to set the Chinese language for the mobile game Call of Duty: Warzone 1. First enter the game and click the settings icon in the upper right corner of the interface. 2. In the menu bar that appears, find the [Download] option and click it. 3. Select [SIMPLIFIEDCHINESE] (Simplified Chinese) on this page to download the Simplified Chinese installation package. 4. Return to the settings

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

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

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

Excel spreadsheet is one of the office software that many people are using now. Some users, because their computer is Win11 system, so the English interface is displayed. They want to switch to the Chinese interface, but they don’t know how to operate it. To solve this problem, this issue The editor is here to answer the questions for all users. Let’s take a look at the content shared in today’s software tutorial. Tutorial for switching Excel to Chinese: 1. Enter the software and click the "File" option on the left side of the toolbar at the top of the page. 2. Select "options" from the options given below. 3. After entering the new interface, click the “language” option on the left

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

"WWE2K24" is a racing sports game created by Visual Concepts and was officially released on March 9, 2024. This game has been highly praised, and many players are eagerly interested in whether it will have a Chinese version. Unfortunately, so far, "WWE2K24" has not yet launched a Chinese language version. Will wwe2k24 be in Chinese? Answer: Chinese is not currently supported. The standard version of WWE2K24 in the Steam Chinese region is priced at 199 yuan, the deluxe version is 329 yuan, and the commemorative edition is 395 yuan. The game has relatively high configuration requirements, and there are certain standards in terms of processor, graphics card, or running memory. Official recommended configuration and minimum configuration introduction:

balatro settings Chinese method balatro settings Chinese method Mar 07, 2024 pm 09:10 PM

The default language of the balatro game is English, but players can set the language to Chinese in Steam. Some players still don’t know how to set it. Here is how to set balatro to Chinese. How to set up balatro in Chinese 1. First open Steam, click on the library, find balatro, right-click and select properties. 2. You can see the language in the properties interface, click to enter the language setting interface. 3. Players can set the language of the game to Simplified Chinese or other languages. 4. Afterwards, players need to restart Steam, and then enter the game to see that it is already in Chinese. The above is how to set Chinese in balatro. It is relatively simple. Players can try it.

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 written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text

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 Chinese to English in Google Chrome? Some friends want to set Google Chrome to English so that they can continuously improve their English during use. So how to set it to English? Google Chrome is Chinese by default. Below, I will show you how to set the language of Google Chrome to English. Let’s take a look. Setting steps: 1. Open [Google Chrome], as shown in the figure below. 2. Click the [three dots] menu in the upper right corner of the Google Chrome interface, as shown in the figure below. 3. After entering the menu page, find [Settings], as shown in the figure below. 4. After entering the settings page, click the [Language] option, as shown in the figure below. 5. Select [Add Language] in the language interface, as shown in the figure below.

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

Title: Methods and code examples to solve the problem of garbled characters when importing Chinese data into Oracle. When importing Chinese data into Oracle database, garbled characters often appear. This may be due to incorrect database character set settings or encoding conversion problems during the import process. . In order to solve this problem, we can take some methods to ensure that the imported Chinese data can be displayed correctly. The following are some solutions and specific code examples: 1. Check the database character set settings In the Oracle database, the character set settings are

See all articles