Thread Hilfe bei charset und use utf8 (10 answers)
Opened by bianca at 2014-07-09 19:10

bianca
 2014-07-10 10:21
#176363 #176363
User since
2009-09-13
6991 Artikel
BenutzerIn

user image
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
2
3
4
5
6
7
8
####################
Zeile 24
{"1":"\"öäüÖÄÜ€@ß\"","2":"\"öäüÖÄÜ@€ß\""}
####################
Zeile 29
"öäüÖÄÜ€@ß""öäüÖÄÜ@€ß"
####################
Zeile 32


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
2
3
4
5
6
7
8
9
####################
Zeile 25
{"1":"\"öäüÖÄÜ€@ß\"","2":"\"öäüÖÄÜ@€ß\""}
####################
Zeile 30
"öäüÖÄÜ€@ß""öäüÖÄÜ@€ß"
####################
Zeile 34
"ö__ÖÄÜ€@ß""ö__ÖÄÜ@€ß"
10 print "Hallo"
20 goto 10

View full thread Hilfe bei charset und use utf8