我正在从android mobile获取数据,我将其存储在mysql db中,然后我必须在网页上显示该数据。它适用于英文字符,但不适用于其他外语字符(例如阿拉伯语,波斯语,卡纳达语等)。因此,我决定从手机以base64格式发送,我将其以base64格式存储在mysql db中,并且在网页上显示时,我将其从base64解码回正常字符,但无法正常工作。它以这种格式显示:

Ùا Ù٠اÙØ´Ùرة اÙÙÙحدة "ÙÙÙÙÙÙد" Ø


Perl中使用的代码:

my $cgi = new CGI '-utf8';
use MIME::Base64;
binmode STDOUT, ":utf8";
use Encode 'decode_utf8';

print $cgi->header(
-type => 'text/html',
-charset => 'utf8',
);


print qq~<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>~;

print decode_base64("2YXYpyDZh9mKINin2YTYtNmB2LHYqSDYp9mE2YXZiNit2K/YqSAi2YrZiNmG2ZDZg9mI2K8iINif");

print qq~</body></html>~;


encode_base64会转换回阿拉伯字符,但在浏览器中不起作用。

有什么我想念的东西吗?或者无法在数据库的base64中存储阿拉伯字符并将其即时转换为html?

最佳答案

我删除了binmode STDOUT, ":utf8";后,它的工作原理如下:

#!/usr/bin/perl

use CGI;

my $cgi = new CGI;
use MIME::Base64;

print $cgi->header(
-charset => 'utf8',
);

print qq~<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html> <meta name="description" content="Displaying foreign languages with incompatible character sets using Unicode."/>
</head>
<body>~;
print decode_base64("2YXYpyDZh9mKINin2YTYtNmB2LHYqSDYp9mE2YXZiNit2K/YqSAi2YrZiNmG2ZDZg9mI2K8iINif");

print qq~</body></html>~;

09-20 21:16