Problem with charset
Moderator: General Moderators
Problem with charset
in my localhost when i un my script i see greek, but when i upload my perl script to the remote server instead of seeing greek i see some weird characters instead
can anyonte tell me how to correct this?
can anyonte tell me how to correct this?
probably you have to set a proper charset
http://www.w3.org/TR/REC-html40/charset.html#h-5.2.2
http://www.w3.org/TR/REC-html40/charset.html#h-5.2.2
volka glad to see u r back man! how was your holdidays?
well, i managed finally to convert my php script to perl: here ir is:
I have 3 problems now.... 
a) i cant set the character set although i have found the correct one
b) in my localhost when i try from the browser to get http://localhost/index.pl it asks me if it should open the file intead of display it and
c) do i have correct tha mial syntax in my script?
well, i managed finally to convert my php script to perl: here ir is:
Code: Select all
#!/usr/bin/perl
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use Socket;
use DBI;
use DBD::mysql;
$xronos = localtime; $i=0;
$host = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}), AF_INET);
$db = DBI->connect("DBI:mysql:nik_db", {RaiseError => 1}) or
$db = DBI->connect("DBI:mysql:nik_db", "nik", "macgyver", {RaiseError => 1});
print header(), start_html( {-title => "Didaxes Agion Pateron", -background => "http://localhost/images/anemos.jpg"} );
open(IN, "data.txt") || die $!;
@data = <IN>;
close(IN);
$data = join("", @data);
$data =~s/\n//g;
#*******************************************************************************
print <<ENDOFHTML;
<html><head><title></title>
<script type="text/javascript">
var textToShow = "$data";
var pos = 0;
var tm;
function init()
{ tm = setInterval("type()", 50) }
function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("divText");
c = textToShow.charAt(pos++);
if (c.charCodeAt(0) != 13)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));
}
else
clearInterval(tm);
}
</script>
<center><font size=5 color=LightGreen>- H Euxi tou Ihsou -<br><br>
<body background=images/anemos.jpg onload=javascript:init()>
<center>
<div id="DivText" align="Left" style="
background: url(http://localhost/images/blueblack.jpg);
border-color: Yellow;
border-style: Groove;
border-width: 10;
width: 900;
height: 500;
color: LightBlue;
font-face: Com;
font-size: 19">
</div>
</body>
</html>
ENDOFHTML
#*******************************************************************************
print start_form(), br();
print table( {-border => 5, -align => "center", -background => "http://localhost/images/blue.jpg"},
Tr( th( h2( "Pos se lene file?" ), th( textfield( "onoma" ) ) ) ),
Tr( th( h2( "Poio einai to sxolio sou?" ), th( textarea( -name => "sxolio", -rows => 4, -columns => 25 ) ) ) ),
Tr( th( h2( "Poio einai to e-mail sou?" ), th( textfield( "email" ) ) ) ),
Tr( th( submit( "Emfanisi" ), th( submit( "Apostoli" ) ) ) ) );
print end_form(), br();
open(IN, "tips.txt") || die $!;
@tips = <IN>;
close(IN);
$tips = $tipsїint(rand(@tips))];
print table( {-border => 5, -align => "center", -background => "http://localhost/images/blueblack.jpg"},
Tr( th( h4( {-align => "center"}, $tips ) ) ) );
$sql = "UPDATE counter SET visitor = visitor + 1";
$db->do( $sql );
$st = $db->prepare( "SELECT visitor FROM counter" );
$st->execute();
@visitor = $st->fetchrow_array();
print h3( {-align => "center"}, $xronos);
print h3( {-align => "center"}, $host);
print h3( {-align => "center"}, $visitorї0]);
print a( {href => "http://www.jokes.gr"}, img {src => "http://localhost/images/cross.gif"} );
exec('mail nik0s@mycosmos.gr');a) i cant set the character set although i have found the correct one
b) in my localhost when i try from the browser to get http://localhost/index.pl it asks me if it should open the file intead of display it and
c) do i have correct tha mial syntax in my script?
adding charset definition to the html-output: http://stein.cshl.org/WWW/software/CGI/#header
I can't remember: Do you have full control of the server in use or just a shared account, i.e. do you administer that box yourself?
If you do you should set up your webserver to handle your perl-files as scripts otherwise they are send as text/plain or application/occtet
http://perl.apache.org/docs/2.0/user/config/config.html tells you how to do so
I can't remember: Do you have full control of the server in use or just a shared account, i.e. do you administer that box yourself?
If you do you should set up your webserver to handle your perl-files as scripts otherwise they are send as text/plain or application/occtet
http://perl.apache.org/docs/2.0/user/config/config.html tells you how to do so
man pls give me a hand heer i ve trying for dayts for this and i cant meke tha DAMN thing work!!
here is my code so far, the one we were talking about.....
Pls make it to shwo greek and feel free to correct ig u see any mistake...
thanks one more time...
sometime docs dont help me....
here is my code so far, the one we were talking about.....
Code: Select all
#!/usr/bin/perl
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use Socket;
use DBI;
use DBD::mysql;
$xronos = localtime; $i=0;
$host = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}), AF_INET);
$db = DBI->connect("DBI:mysql:nik_db", {RaiseError=>1}) or
$db = DBI->connect("DBI:mysql:nik_db", "nik", "macgyver", {RaiseError=>1});
print header(), start_html( -lang=>'el', -title=>"Didaxes Agion Pateron", -background=>"http://localhost/images/anemos.jpg" );
open(IN, "data.txt") || die $!;
@data = <IN>;
close(IN);
$data = join("", @data);
$data =~s/\n//g;
#*******************************************************************************
print <<ENDOFHTML;
<html><head><title></title>
<script type="text/javascript">
var textToShow = "$data";
var pos = 0;
var tm;
function init()
{ tm = setInterval("type()", 50) }
function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("divText");
c = textToShow.charAt(pos++);
if (c.charCodeAt(0) != 13)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));
}
else
clearInterval(tm);
}
</script>
<center><font size=5 color=LightGreen>- H Euxi tou Ihsou -<br><br>
<body background=images/anemos.jpg onload=javascript:init()>
<center>
<div id="DivText" align="Left" style="
background: url(http://localhost/images/blueblack.jpg);
border-color: Yellow;
border-style: Groove;
border-width: 10;
width: 900;
height: 500;
color: LightBlue;
font-face: Com;
font-size: 19">
</div>
</body>
</html>
ENDOFHTML
#*******************************************************************************
print start_form(), br();
print table( {-border=>5, -align=>"center", -text=>"yellow", -background=>"http://localhost/images/brick.gif"},
Tr( th( p( "Pos se lene file?" ), th( textfield( "onoma" ) ) ) ),
Tr( th( p( "Poio einai to sxolio sou?" ), th( textarea( -name=>"sxolio", -rows=>4, -columns=>25 ) ) ) ),
Tr( th( p( "Poio einai to e-mail sou?" ), th( textfield( "email" ) ) ) ),
Tr( th( submit( "Emfanisi" ), th( submit( "Apostoli" ) ) ) ) );
print end_form(), br();
open(IN, "tips.txt") || die $!;
@tips = <IN>;
close(IN);
@tips = grep { !/^\s*\z/s } @tips;
$tips = $tipsїint(rand(@tips))];
print table( {-border=>5, -align=>"center", -text=>"pink", -background=>"http://localhost/images/blue.jpg"},
Tr( th( p( {-align=>"center"}, $tips ) ) ) );
$sql = "UPDATE counter SET visitor = visitor + 1";
$db->do( $sql );
$st = $db->prepare( "SELECT visitor FROM counter" );
$st->execute();
@visitor = $st->fetchrow_array();
print h3( {-align=>"center"}, $xronos);
print h3( {-align=>"center"}, $host);
print h3( {-align=>"center"}, $visitorї0]);
print a( {href=>"http://www.psyche.gr"}, img {src=>"http://localhost/images/cross.gif"} );
#system("mail -s $host nik0s\@mycosmos.gr");thanks one more time...
sometime docs dont help me....
add the -charset parameter to header() as described in http://stein.cshl.org/WWW/software/CGI/#headerprint header(), start_html( -lang=>'el', -title=>"Didaxes Agion Pateron", -background=>"http://localhost/images/anemos.jpg" );
yeap! now its wotking right....
all it was need ed was this
print header( -charset=>"iso-8859-7" ), start_html( -title=>"Didaxes Agion Pateron", -background=>"http://localhost/images/anemos.jpg" );
not even the -lang=>"el"
i cant beleive it......
now am having problems with javascript
it wont display the text inseide the blue box
check my website pls at
http://www.hostgreece.com/~nik/cgi-bin/index.pl
all it was need ed was this
print header( -charset=>"iso-8859-7" ), start_html( -title=>"Didaxes Agion Pateron", -background=>"http://localhost/images/anemos.jpg" );
not even the -lang=>"el"
i cant beleive it......
now am having problems with javascript
it wont display the text inseide the blue box
check my website pls at
http://www.hostgreece.com/~nik/cgi-bin/index.pl
I don't think you can have multiline string literals in a javascript block like in php,e.g.
tryinstead
Code: Select all
<?php
$text = "Line1
Line2";
?>Code: Select all
$data = join("", @data);
$data =~s/\n/"+String.fromCharCode(13)+"/g;
$data =~s/\r//g;