Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-06 20:17:34
Original
1538 people have browsed it

这篇文章主要介绍了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程序设计有所帮助。

source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!