2017-03-29 4 views
-3

이 스크립트는 이전 버전의 스크립트라는 것을 알고 있지만, 제대로 작동하려면 도움을 청하는 데 감사드립니다. 몇 년 전만해도 이 좋았지 만 요즘은 재미있어하고 있습니다. 서식을 제발 ....악센트 부호가있는 문자 표시를 수정하려면 어떻게합니까?

브라우저에서 실행할 때 프랑스어 악센트 부호가있는 문자 이 제대로 표시되지 않습니다. 그러나 생성하는 텍스트 파일에서 그들은 잘 보입니다. 여기서 무슨 일이 일어나고있는거야? Hélène Rollan 및 파일 : Hélène Rollan

브라우저에서

: Coeur à l`écoute 및 파일 : Coeur à l`écoute

펄 버전 v5.20.2 내 데이터베이스 utf8_unicode_ci이 표는 브라우저에서

을 utf8_unicode_ci되고, MySQL은입니다

#!/usr/bin/perl -- 
use utf8; 
use CGI::Carp qw(fatalsToBrowser); 
use CGI qw (:standard); 
$q = new CGI; 
use Encode; 
use open ':encoding(utf8)'; 
binmode(STDOUT, ":unix:utf8"); 

$user = "manager"; 

require "config.cgi"; 
&Create_DB_Connection; 
$time = time(); 

sub Create_DB_Connection{ 
    use DBI; 
    $DSN = "DBI:mysql:$mysql_database:$mysql_hostname"; 
    $dbh = DBI->connect($DSN, "$mysql_username", "$mysql_password", {mysql_enable_utf8 => 1}) || die return; 
    if ($dbh) { $connected = "YES"; } 
    return; 
} 

sub Do_SQL{ 
    eval{ 
    $sth = $dbh->prepare($SQL); 
    }; 
$dbh->do(qq{SET NAMES 'utf8';}); 
    $sth->execute; 
    return ($sth); 
} 

    &downline; 

# Prepare and show tree of affiliates 
sub downline { 
($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time()); 
$month = $mon; 
$year = $year + 1900; 
print $q->header; 

print<<EOF; 
    <HTML><HEAD><TITLE>Network Summary</TITLE> 
<meta http-equiv="Content-type" content="text/html;charset=utf-8" /> 
</HEAD> 
<style type="text/css"> 
<!-- 
A:visited {text-decoration: none;} 
A:hover {text-decoration: underline;} 
A:link {text-decoration: none;} 
A:active {text-decoration: none;} 
.MEMBERS {font-size: 8pt; text-decoration: none; font-family: Verdana,verdana; color: FF0000;} 
--> 
</style> 
<BODY BGCOLOR="FFFFFF" TEXT="000000" LINK="000080" VLINK="004080"> 
<center><font size=4 face=arial color=000000><b>Network Summary as of $month/$year</b><br> 
<font face=verdana,arial size=1><a href=wmstats_en2.cgi>[return to main page]</a></font></center> 
<p> 
EOF 

$featured_file = "/home/bruce/data/featured.txt"; 

$SQL="SELECT FIRST_NAME,LAST_NAME,SPONSOR_ID,CO_SPONSOR_ID,ID FROM main_members"; 
&Do_SQL; 
    while ($row = $sth->fetchrow_hashref){ 
    $info{$row->{'ID'}} = [$row->{'FIRST_NAME'},$row->{'LAST_NAME'},$row->{'SPONSOR_ID'}]; 
    push @{ $kids{$row->{'CO_SPONSOR_ID'}} }, $row->{'ID'}; 
} 
$kid = "$user"; 

if (!$kids{$kid}) { 
print<<EOF; 
<center><b><font size=2 face=arial>There are currently no members in your downline</font></b><font size=4 face=arial color=000000><br><BR> 
EOF 
} else { 
&crunch(1); 
} 

$o++; 

sub crunch { 

foreach $kid (@{ $kids{$kid} }) { 
$newlevel++; 
$payouts{$newlevel}++; 
$levels{$newlevel}++; 
$total_downline++; 
while ($b < $newlevel) { $report .= "&nbsp;&nbsp;&nbsp;&nbsp;"; $b++; } $b=0; 
$report .= "$newlevel: $kid - $info{$kid}[0] $info{$kid}[1] <br>"; 

# I added this to generate a text file 
open (FILE, ">>$featured_file"); 
flock(FILE, 2); 
print FILE "$newlevel: $kid - $info{$kid}[0] $info{$kid}[1] \n"; 
flock(FILE, 8); 
close (FILE); 

&crunch($newlevel); 
$newlevel--; 
delete($info{$kid}); 
} 
} 
print<<EOF; 
<center><table><tr><td valign=top nowrap> 
<font face=verdana size=2> 
$report 
</td><td valign=top> 
<table cellpadding=0><tr> 
<td align=right nowrap><font face=verdana,arial size=2><b>Total Downline:<p>&nbsp;</td><td><font face=verdana,arial size=2><b>&nbsp; $total_downline<p>&nbsp;</td></tr> 
EOF 

while (!$found_some) { $i++; 
if ($levels{$i}) { 
print<<EOF; 
<tr><td align=right><font face=verdana,arial size=2><b>Level $i:</td><td><font face=verdana,arial size=2><b>&nbsp; $levels{$i}</td></tr> 
EOF 
} else { $found_some = 1; } 
} 

print<<EOF; 
</td></tr></table> 
<p><font face=verdana size=2><b> 
</TD></TR></TABLE></TD></TR></TABLE> 
EOF 
} 
+0

10 줄까지 줄일 수 있습니까? – ikegami

+0

데이터베이스에서 데이터가 정확한지 확인하기 위해'HEX (the_field_in_question) 선택'출력을 제공해 주시겠습니까? – ikegami

답변

1

관련없는 비트를 제거하고 문제를 해결 한 후 다음을 얻습니다. (당신이 질문 자체에서 관련이없는 비트를 제거했다면, 차이를 참조하는 것이 더 쉽습니다.)

# Specifies the file is encoded using UTF-8. 
# This doesn't matter for this program. 
use utf8; 

# Set the encoding for STDIN, STDOUT and STDERR. 
# Set the default encoding for file handles. 
use open ':std', ':encoding(utf-8)'; 

use CGI  qw(); 
use DBI  qw(); 
use FindBin qw($RealBin); 
use Template qw(); 

my $cgi = CGI->new(); 

my $dbh = DBI->connect(
    "dbi:mysql:...", 
    "...", 
    "...", 
    { 
     RaiseError => 1, 
     PrintError => 0, 
     PrintWarn => 1, 

     # Decodes strings from the database. 
     # Specifying this now performs SET NAMES 'UTF8' 
     mysql_enable_utf8 => 1, 
    }, 
); 

my $val = $dbh->selectrow_array('SELECT ...'); 

{ 
    open(my $fh, '>', '...') 
     or die(...); 

    print($fh $val); 
} 

{ 
    print $cgi->header('text/html; charset=UTF-8'); 

    my %vars = (
     val => $val, 
    ); 

    my $tt = Template->new({ 
     ENCODING  => "UTF-8", 
     INCLUDE_PATH => "$RealBin/tmpl", 
    }); 

    $tt->process('test.tmpl', \%vars) 
     or die($tt->error()); 
} 

tmpl/test.tmpl :

물론,
<html> 
<head> 
<title>Test</title> 
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"> 
</head> 
<body> 
[% val | html %] 
</body> 
</html> 

의의 데이터를 가정 데이터베이스가 정확합니다. 이 사실을 확인해 달라는 요청에 응답하지 않았습니다.

+0

크런치 루틴 내 코드와 같이 제휴 트리가 계산되지 않는 경우를 제외하고는 문제가 없습니다. – musicweb

+3

그래서 뭐? 그것은 당신의 문제와 관련이 없습니다. 다시 말하지만, 귀하의 문제를 * 최소 * 시연하도록 질문을 수정하십시오 – ikegami

+0

도와 주셔서 감사합니다 ... – musicweb

관련 문제