Home php教程 php手册 PHP采用get获取url汉字出现乱码的解决方法

PHP采用get获取url汉字出现乱码的解决方法

Jun 06, 2016 pm 08:17 PM
get php url Garbled characters Chinese character Obtain Solution

这篇文章主要介绍了PHP采用get获取url汉字出现乱码的解决方法,是很多PHP程序员都曾遇到的问题,非常具有实用价值,需要的朋友可以参考下

本文实例讲述了PHP采用get获取url汉字出现乱码的解决方法。分享给大家供大家参考。具体方法如下:

一、问题:

本来打算这样使用

复制代码 代码如下:

[查看辖区动态]


结果在list.php页面得到的是—–查看[辖区动怿]
一开始猜想可能是汉字的“态"这个编码和某些东西冲突了,,所以出现乱码。

二、解决方法:

使用:

复制代码 代码如下:

" charset="utf-8" target="main">[查看]


然后在list.php页面这样用

复制代码 代码如下:


header("Content-type: text/html; charset=utf-8");
if($_GET['plate'])
echo $plate=urldecode($_GET['plate']);
?>


也就不会乱码和传递不正常了。
注意此处的接收GET页面编码需要和发送端一致!

关于string urlencode ( string $str )函数

此函数便于将字符串编码并将其用于 URL 的请求部分,同时它还便于将变量传递给下一页。
示例1 urlencode()

复制代码 代码如下:

echo '';
?>


示例2 urlencode() 与 htmlentities()

复制代码 代码如下:

$query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);
echo '';
?>

希望本文所述对大家的PHP程序设计有所帮助。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Apr 06, 2025 am 12:07 AM

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

How to obtain real-time application and viewer data on the 58.com work page? How to obtain real-time application and viewer data on the 58.com work page? Apr 05, 2025 am 08:06 AM

How to obtain dynamic data of 58.com work page while crawling? When crawling a work page of 58.com using crawler tools, you may encounter this...

How to select a child element with the first class name item through CSS? How to select a child element with the first class name item through CSS? Apr 05, 2025 pm 11:24 PM

When the number of elements is not fixed, how to select the first child element of the specified class name through CSS. When processing HTML structure, you often encounter different elements...

What is the reason for encoding exceptions when using the request library to get HTML text in Node.js? How to solve it? What is the reason for encoding exceptions when using the request library to get HTML text in Node.js? How to solve it? Apr 05, 2025 am 07:03 AM

The reason and solution for coding exceptions when using the request library to obtain HTML text content in the Node.js environment. During the development process of using Node.js, it is often necessary to...

Why does negative margins not take effect in some cases? How to solve this problem? Why does negative margins not take effect in some cases? How to solve this problem? Apr 05, 2025 pm 10:18 PM

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...

Why does a specific div element in the Edge browser not display? How to solve this problem? Why does a specific div element in the Edge browser not display? How to solve this problem? Apr 05, 2025 pm 08:21 PM

How to solve the display problem caused by user agent style sheets? When using the Edge browser, a div element in the project cannot be displayed. After checking, I posted...

See all articles