- 论坛徽章:
- 0
|
本帖最后由 youzhengchuan 于 2014-02-19 15:59 编辑
看来这种不怎么热的东西,还是要自己摸索,解决方法如下:
1: 引用 “Mojo::ByteStream”
2:读取类容之后,需要进行UTF-8的解码。(不知道为什么需要解码,因为文本内容原本就是UTF-8的。可能是mojo会自行再做一次UTF-8的编码吧,所以如果原类容是UTF-8的,那么mojo输出之后,就等于多做了一次UTF-8编码。)
可以看这个连接”https://github.com/kraih/mojo/wiki/Utf-8-manipulation“,在这里讲如何使用UTF-8,我就是在这里看到了”Mojo::ByteStream“函数。
- 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/>
复制代码 |
|