- 论坛徽章:
- 0
|
原帖由 yhsmengdi 于 2006-9-7 13:57 发表
在win2003下,安装了apache2.2 ,perl 5.8.8。
当我在 URL 中传递一个参数,如: test.cgi?title=我的测试
接收到的参数为乱码
谁能告诉我怎么修改啊!
谢谢
Hallo,
Apache will automatically encoded the query string "title=我的测试" as URI-Encoding
string as following:
$ENV{QUERY_STRING} = title=%E6%88%91%E7%9A%84%E6%B5%8B%E8%AF%95
using the method uri_unescape from URI::Escape to decode the querystring, as default
the decode string is UTF-8 fomat.
In order to display in chinese, you must use Encode::decode('UTF-8', STRING) and then
Encode::encode('GB2312', STRING) again.
here is demo code test.cgi again:
and point the browser to /cgi-bin/test.cgi?title=我的测试
- #!/usr/bin/perl -w
- use strict;
- use URI::Escape;
- use Encode;
- my $qstr = '';
- my $unescaped_qstr = '';
- print qq(Content-type: text/html; charset=GB2312);
- print qq(\n\n);
- if ($ENV{'QUERY_STRING'}) {
- $qstr = $ENV{'QUERY_STRING'};
- $unescaped_qstr = uri_unescape($qstr);
- print "query: uri-encoded: $qstr<br>\n";
- print "uri-unescaped as utf-8: $unescaped_qstr<br>\n";
- print "show GB2312:", encode('GB2312', decode("UTF-8", $unescaped_qstr)), "<br>\n";
- }
- else {
- print "no query string<br>\n";
- }
复制代码
regards, ulmer |
|