PHP采用get获取url汉字出现乱码的解决方法
这篇文章主要介绍了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程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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 dynamic data of 58.com work page while crawling? When crawling a work page of 58.com using crawler tools, you may encounter this...

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...

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...

iconfont...

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

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...
