2014-07-10 148 views
0

我從android手機獲取數據,我將它存儲在mysql數據庫中,然後我必須在網頁上顯示它。它適用於英文字符,但不適用於其他外語字符(如阿拉伯語,波斯語,卡納達語等)。所以我決定從手機發送base64格式,我將它以base64格式存儲在mysql數據庫中,並且在網頁上顯示時,我將它從base64解碼回普通字符,但這不起作用。它顯示格式爲:Perl中從Base64到HTML的阿拉伯字符

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

代碼:

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?

回答

0

它的工作我去掉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>~;