系统写入中的Perl、Starman Unicode宽字符

系统写入中的Perl、Starman Unicode宽字符,perl,unicode,html-entities,mason,Perl,Unicode,Html Entities,Mason,我有一个单词comЯade,但我不能用HTML打印,因为俄文字母。。。我 尝试: 然后我试着: $str =~ s/1071/&#1071;/g; $str =~ s/Я/&#1071;/g; $str =~ s/ï/&#1071;/g; 但在这两种情况下,我都会遇到这样的错误: 在/usr/local/share/perl/5.10.1/Starman/Server.pm行470的syswrite中使用宽字符。 <head> <

我有一个单词comЯade,但我不能用HTML打印,因为俄文字母。。。我 尝试:

然后我试着:

$str =~ s/1071/&#1071;/g;
$str =~ s/Я/&#1071;/g;
$str =~ s/ï/&#1071;/g;    
但在这两种情况下,我都会遇到这样的错误:

在/usr/local/share/perl/5.10.1/Starman/Server.pm行470的syswrite中使用宽字符。

<head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
为什么?

一些代码:

title.mi

<%init>
binmode STDOUT, ':encoding(UTF-8)';
($str =~ s/&/%26/g;); #this is working
$str =~ s/1071/&#1071;/g;
$str =~ s/Я/&#1071;/g;
$str =~ s/ï/&#1071;/g;
</%init>
<div class="bd-headline left">
<h1 style="margin-top:0; padding-top:0;"> <% $str %> </h1>
</div>

二进制模式标准输出':编码(UTF-8)';
($str=~s/&/%26/g;)#这是有效的
$str=~s/1071/Я/G
$str=~s/Я/Я/G
$str=~s/Ã′/Я/G
base.mc

<head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

问题1:

如果您的源代码是使用UTF-8编码的,那么您没有通过使用
useUTF8告诉Perl那么多

如果您的源代码没有使用UTF-8编码,那么它不可能包含“Я”


问题2:

文件句柄只能传输字节,但不能将Unicode字符编码为字节。这是通过使用字符编码(如UTF-8)实现的。您的文档指定使用什么编码?使用它对输出进行如下编码:

binmode STDOUT, ':encoding(UTF-8)';
问题1:

如果您的源代码是使用UTF-8编码的,那么您没有通过使用
useUTF8告诉Perl那么多

如果您的源代码没有使用UTF-8编码,那么它不可能包含“Я”


问题2:

文件句柄只能传输字节,但不能将Unicode字符编码为字节。这是通过使用字符编码(如UTF-8)实现的。您的文档指定使用什么编码?使用它对输出进行如下编码:

binmode STDOUT, ':encoding(UTF-8)';

用html实体替换字符来转义字符几乎从来都不是正确的做法


底层服务器(catalyst?)可能不支持unicode。搜索CPAN berings的Catalyst::Plugin::Unicode::Encoding可能会有所帮助。

用html实体替换字符来转义字符几乎从来都不是正确的做法

底层服务器(catalyst?)可能不支持unicode。搜索CPAN将启动Catalyst::Plugin::Unicode::Encoding,这可能会有所帮助。

一些代码:

title.mi

<%init>  
        use Encode;
        my $hl = encode_utf8($str);  
        my $find = "&#1071;";   
        my $replace = "Я";  
        $hl =~ s/$find/$replace/g; 
        my $hs = HTML::Strip->new();
        my $no_html_hl = $hs->parse($hl); 
</%init>
<div class="bd-headline left">
            <h1 style="margin-top:0; padding-top:0;"> <% $no_html_hl %> </h1>
</div>

使用编码;
my$hl=encode_utf8($str);
我的$find=“Я;”;
我的$replace=“Я”;
$hl=~s/$find/$replace/g;
my$hs=HTML::Strip->new();
我的$no\u html\u hl=$hs->parse($hl);
base.mc

<head>    </head>  

有帮助。

一些代码:

title.mi

<%init>  
        use Encode;
        my $hl = encode_utf8($str);  
        my $find = "&#1071;";   
        my $replace = "Я";  
        $hl =~ s/$find/$replace/g; 
        my $hs = HTML::Strip->new();
        my $no_html_hl = $hs->parse($hl); 
</%init>
<div class="bd-headline left">
            <h1 style="margin-top:0; padding-top:0;"> <% $no_html_hl %> </h1>
</div>

使用编码;
my$hl=encode_utf8($str);
我的$find=“Я;”;
我的$replace=“Я”;
$hl=~s/$find/$replace/g;
my$hs=HTML::Strip->new();
我的$no\u html\u hl=$hs->parse($hl);
base.mc

<head>    </head>  


有帮助。

尝试添加binmode标准输出“:编码(UTF-8)”;但仍然有相同的错误。我遗漏了什么?不确定那是什么,但那不是你发布的Perl。您刚才重复了之前在评论中发布的内容,我使用的是mason 2(perl+html)。我从数据库收到一个字符串(标题)并正在打印它。尝试添加binmode标准输出“:encoding(UTF-8)”;但仍然有相同的错误。我遗漏了什么?不确定那是什么,但那不是你发布的Perl。您刚才重复了之前在评论中发布的内容,我使用的是mason 2(perl+html)。我从DB收到一个字符串(标题)并正在打印它。我使用的是mason 2。这是有效的($str=~s/&/%26/g;),我使用的是mason 2。这是有效的($str=~s/&/%26/g;)。