Thread Hilfe bei charset und use utf8
(10 answers)
Opened by bianca at 2014-07-09 19:10
OK, neues Script 1:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #!/usr/bin/perl -w use strict 1.04; use warnings 1.06; use CGI 3.52; use LWP::UserAgent; use HTTP::Request::Common 'POST'; use JSON 2.53; use Text::Iconv; use Data::Dumper; use 5.010; # dieses Script wird in Notepad++ als "ANSI" gespeichert open(my $f,">test_charset_debug.txt"); my $test = POST( 'http://www.lokalerserver.de/test_charset2.pl', Content_Type => 'form-data', Content => [ dummy => 'foo', ], ); my $userAgent = LWP::UserAgent->new(); my $response = $userAgent->request($test); my $content = $response->decoded_content; say $f ('#'x20)."\nZeile ".__LINE__."\n$content"; my $ref = JSON->new->utf8->decode($content); my %test = %$ref; my $out = ''; foreach my $k (keys %test) { $out .= $test{$k} } say $f ('#'x20)."\nZeile ".__LINE__."\n$out"; my $converter = Text::Iconv->new('UTF-8','ISO-8859-15'); $out = $converter->convert($out); say $f ('#'x20)."\nZeile ".__LINE__."\n$out"; print STDOUT CGI->new->header(-charset=>'ISO-8859-15').<<HTML_TEIL <doctype html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=ISO-8859-15"> </head> <body> <pre>$out</pre> </body> </html> HTML_TEIL ; Ergebnis mit UTF-8 bei JSON: #################### Zeile 24 {"1":"\"öäüÖÄÜ€@ß\"","2":"\"öäüÖÄÜ@ۧ\""} #################### Zeile 29 "öäüÖÄÜ€@ß""öäüÖÄÜ@ۧ" #################### Zeile 32 "öäüÖÄܤ@ß""öäüÖÄÜ@¤ß" Ergebnis mit ->utf8(0): Code: (dl
)
1 #################### Test mit Code (perl): (dl
)
1 2 3 4 #my $converter = Text::Iconv->new('UTF-8','ISO-8859-15'); #$out = $converter->convert($out); $out = encode('ISO-8859-15',$out); say $f ('#'x20)."\nZeile ".__LINE__."\n$out"; Code: (dl
)
1 #################### 10 print "Hallo"
20 goto 10 |