在json中不支持中文,用它传送中文数据就会出现数据丢失或者乱码,必须在传送前对要发送的字符串进行编码,由于传送过去需要用js进行数据解析,考虑到js中有unescape函数,故若在php中有个escape函数,对数据进行编码,在客户端用unescape进行 解码,这样就会方便很多。
urldecode
(PHP 4, PHP 5)
urldecode — 解码已编码的 URL 字符串
范例
Example #1 urldecode() 示例
<?php
$query = "my=apples&are=green+and+red";
foreach (explode('&', $query) as $chunk) {
$param = explode("=", $chunk);
if ($param) {
printf("Value for parameter \"%s\" is \"%s\"<br/>\n", urldecode($param[0]), urldecode($param[1]));
}
}
?>
参见
- urlencode() - 编码 URL 字符串
- rawurlencode() - 按照 RFC 1738 对 URL 进行编码
- rawurldecode() - 对已编码的 URL 字符串进行解码
- » RFC 3986
}
chrisstocktonaz at gmail dot com
3 years ago
I was looking for a fast way to build a string dsn from a key => value pair array. I came up with the following, simple enough for my purposes.
<?php
$dsn = Array(
'host' => 'localhost',
'port' => 80,
'user' => 'foo',
'pass' => 'R(I%!JAKSJ(asd'
);
$dsn = urldecode(http_build_query($dsn, NULL, ';'));
var_dump($dsn); // host=localhost;port=80;user=foo;pass=R(I%!JAKSJ(asd
?>