Thread: [htmltmpl] Help! Chinese character displaying problem using HTML::TEMPLATE
Brought to you by:
samtregar
|
From: Allen Z. <act...@gm...> - 2008-03-14 09:06:54
|
Hi all,
My cgi script using Html::Template having some error display Chinese
Character.
I have set character set to gb2312, and the encoding character set was
set to gb2312 too.
But in that case, the "你好" wasn't displayed as expected.
However, I found that if I change the encoding character set of my *
browser* to utf8, it displays perfectly.
Why ?
Most browsers in China were set to gb2312 encoding, I don't want users
to manually change their
default setting to view my page.
What can I do?
Thanks!!
cgi code:
##################################################
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use HTML::Template;
my $template = HTML::Template->new(filename => 'title.tpl.php');
my $title = '你好';
$template->param('title' => $title);
*print header(-charset=>"gb2312");*
print $template->output;
template code:
##################################################
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="description" content="">
<meta name="keywords" content="">
<title><TMPL_VAR NAME=title></title>
</head>
<body>
<TMPL_VAR NAME=title>
<br>
Hello!
<br>
Hard code你好
</BODY>
</HTML>
Allen Zhang |
|
From: Dawid J. <djs...@gm...> - 2008-03-14 12:11:59
|
Hi Allen, You can tell the browser what encoding to use for an HTML document. The first way is to use HTTP Response headers by providing the right Content-Type header example: Content-Typetext/html; charset=UTF-8 The second way is to include it in the HTML document itself as a meta tag <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Accomodation</title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> </head> You should be doing the above anyway as it does not rely on any browser defaults and UTF-8 is the way forward as it does not limit the character set. Regards David ----- Original Message ----- From: Allen Zhang To: htm...@li... Sent: Friday, March 14, 2008 9:06 AM Subject: [htmltmpl] Help! Chinese character displaying problem usingHTML::TEMPLATE Hi all, My cgi script using Html::Template having some error display Chinese Character. I have set character set to gb2312, and the encoding character set was set to gb2312 too. But in that case, the "你好" wasn't displayed as expected. However, I found that if I change the encoding character set of my browser to utf8, it displays perfectly. Why ? Most browsers in China were set to gb2312 encoding, I don't want users to manually change their default setting to view my page. What can I do? Thanks!! cgi code: ################################################## #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use HTML::Template; my $template = HTML::Template->new(filename => 'title.tpl.php'); my $title = '你好'; $template->param('title' => $title); print header(-charset=>"gb2312"); print $template->output; template code: ################################################## <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="description" content=""> <meta name="keywords" content=""> <title><TMPL_VAR NAME=title></title> </head> <body> <TMPL_VAR NAME=title> <br> Hello! <br> Hard code你好 </BODY> </HTML> Allen Zhang ------------------------------------------------------------------------------ ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ ------------------------------------------------------------------------------ _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users |
|
From: Brad B. <bm...@ma...> - 2008-03-14 12:50:45
|
Well, it looks like Allen is in fact telling the browser which encoding to use, both in the header and the document. I think he is trying to figure out why he has to set it to UTF-8 when he believes the text is in gb2312. I believe that perl is printing the text as UTF-8 because it isn't being told otherwise. Regards, -- Brad On Fri, Mar 14, 2008 at 8:11 AM, Dawid Joubert <djs...@gm...> wrote: > Hi Allen, > > You can tell the browser what encoding to use for an HTML document. The > first way is to use HTTP Response headers by providing the right > Content-Type header example: > Content-Typetext/html; charset=UTF-8 > > The second way is to include it in the HTML document itself as a meta tag > > <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> > <head> > <title>Accomodation</title> > * <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> > * > </head> > > You should be doing the above anyway as it does not rely on any browser > defaults and UTF-8 is the way forward as it does not limit the character > set. > > > Regards > David > > > ----- Original Message ----- > *From:* Allen Zhang <act...@gm...> > *To:* htm...@li... > *Sent:* Friday, March 14, 2008 9:06 AM > *Subject:* [htmltmpl] Help! Chinese character displaying problem > usingHTML::TEMPLATE > > Hi all, > > My cgi script using Html::Template having some error display Chinese > Character. > I have set character set to gb2312, and the encoding character set was > set to gb2312 too. > But in that case, the "你好" wasn't displayed as expected. > However, I found that if I change the encoding character set of my * > browser* to utf8, it displays perfectly. > Why ? > Most browsers in China were set to gb2312 encoding, I don't want users > to manually change their > default setting to view my page. > What can I do? > Thanks!! > > > cgi code: > ################################################## > #!/usr/bin/perl -w > > use CGI::Carp qw(fatalsToBrowser); > use CGI qw(:standard); > use HTML::Template; > > my $template = HTML::Template->new(filename => 'title.tpl.php'); > my $title = '你好'; > $template->param('title' => $title); > *print header(-charset=>"gb2312");* > > print $template->output; > > template code: > ################################################## > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> > <meta name="description" content=""> > <meta name="keywords" content=""> > <title><TMPL_VAR NAME=title></title> > </head> > <body> > <TMPL_VAR NAME=title> > <br> > Hello! > <br> > Hard code你好 > </BODY> > </HTML> > > > > Allen Zhang > > ------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > ------------------------------ > > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > > |
|
From: Brad B. <bm...@ma...> - 2008-03-14 12:45:32
|
Hello Allen, You say this: - "I have set character set to gb2312," - "the encoding character set was set to gb2312" But in your cgi code, I don't see any of these: - use Encode; - decode(... - encode(... - open FH ">:encoding(... - use open ':encoding(... So it looks like you aren't telling perl which encoding to use. I'm not an encoding expert by any stretch, but I think that in the absence of your telling perl which encoding to use, it is falling back on UTF-8 (but I'd expect you to see 'wide character' warnings, so maybe I'm wrong). This may be why it looks okay when you set your browser to UTF-8. How to fix? As I said, I'm no expert. If I were you, I'd start reading here: http://perldoc.perl.org/perlunitut.html and follow all the links until it starts to make sense (I'm currently in the process of doing that--again--myself). Hope that helps (hope I'm at least partly correct), -- Brad On Fri, Mar 14, 2008 at 5:06 AM, Allen Zhang <act...@gm...> wrote: > Hi all, > > My cgi script using Html::Template having some error display Chinese > Character. > I have set character set to gb2312, and the encoding character set was > set to gb2312 too. > But in that case, the "你好" wasn't displayed as expected. > However, I found that if I change the encoding character set of my * > browser* to utf8, it displays perfectly. > Why ? > Most browsers in China were set to gb2312 encoding, I don't want users > to manually change their > default setting to view my page. > What can I do? > Thanks!! > > > cgi code: > ################################################## > #!/usr/bin/perl -w > > use CGI::Carp qw(fatalsToBrowser); > use CGI qw(:standard); > use HTML::Template; > > my $template = HTML::Template->new(filename => 'title.tpl.php'); > my $title = '你好'; > $template->param('title' => $title); > *print header(-charset=>"gb2312");* > > print $template->output; > > template code: > ################################################## > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> > <meta name="description" content=""> > <meta name="keywords" content=""> > <title><TMPL_VAR NAME=title></title> > </head> > <body> > <TMPL_VAR NAME=title> > <br> > Hello! > <br> > Hard code你好 > </BODY> > </HTML> > > > > Allen Zhang > > |