Home  >  Article  >  Backend Development  >  PHP采用get获取url汉字出现乱码的解决方法_PHP

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

WBOY
WBOYOriginal
2016-05-31 19:27:54859browse

本文实例讲述了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:
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