- 論壇徽章:
- 0
|
本帖最后由 youzhengchuan 于 2014-02-19 15:59 編輯
看來這種不怎么熱的東西,還是要自己摸索,解決方法如下:
1: 引用 “Mojo::ByteStream”
2:讀取類容之后,需要進(jìn)行UTF-8的解碼。(不知道為什么需要解碼,因為文本內(nèi)容原本就是UTF-8的。可能是mojo會自行再做一次UTF-8的編碼吧,所以如果原類容是UTF-8的,那么mojo輸出之后,就等于多做了一次UTF-8編碼。)
可以看這個連接”https://github.com/kraih/mojo/wiki/Utf-8-manipulation“,在這里講如何使用UTF-8,我就是在這里看到了”Mojo::ByteStream“函數(shù)。
- use Mojo::ByteStream;
- get '/' => sub {
- my $self = shift;
- my $file_utf8 = "/var/www/mojo/app-characterset/Mojolicious-utf8.txt";
- my @content = ();
- if(open FILE,$file_utf8){
- while(<FILE>){
- chomp;
- my $stream = Mojo::ByteStream->new($_);
- my $utf8 = $stream->decode('UTF-8');
- push @content , $utf8;
- }
- $self->stash(content => [@content]);
- }
- } => 'index';
- app->start;
- __DATA__
- @@ index.html.ep
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
- <head/>
- <body>
- <%= link_to 'Back to index/' => '/' %>.<br/>
- <b>is content blow.<b/><br/><br/>
- % foreach ( @$content ){
- % chomp;
- <%= $_ %><br/>
- % }
- <body/>
- <html/>
復(fù)制代碼 |
|