我从 Android 手机获取数据,我将其存储在 mysql 数据库中,然后我必须将其显示在网页上。它适用于英语字符,但不适用于其他外语字符(如阿拉伯语、波斯语、卡纳达语等)。所以我决定从移动设备以base64格式发送,我将其以base64格式存储在mysql数据库中,在网页上显示时,我将其从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>~;
decode_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>~;
关于html - 从 Base64 到 HTML 的阿拉伯字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24669915/