seeker7806
asked on
perl/cgi problem: wrap does not recognize new line or carriage return
Hello:
I previously asked for help for a text wrap code and received great help from you folks on getting the text to wrap. However now, the code is now not recognizing when you hit enter from the keyboard (carriage return). Here is the code:
<code>
$text = $message;
@lines = split(/[\r\n]/, $message);
my @lines2;
s/(.{30})\s+/$1\n/g, push(@lines2, split(/\n/)) foreach @lines;
$lCnt=$#lines2+1;
$container = "/opt/httpd/root-wwwin/htd ocs".$card ToUse;
$font = "/opt/httpd/root-wwwin/htd ocs/tech/p erformance -culture/r ewards/eca rds-master /templ/ver dana.ttf";
$image = GD::Image->newFromJpeg($co ntainer);
$lineStart=80;
$lineHeight=24;
$txtColor = $image->colorResolve(0,0,0 );
for $i (0..$lCnt){
$xPos = 390;
$yPos = $lineStart + ($lineHeight*$i);
@bounds = $image->stringTTF($txtColo r,$font,13 ,0,$xPos,$ yPos,$line s2[$i]);
}
</code>
Thanks in advance for your help.
Regards,
seeker7806
I previously asked for help for a text wrap code and received great help from you folks on getting the text to wrap. However now, the code is now not recognizing when you hit enter from the keyboard (carriage return). Here is the code:
<code>
$text = $message;
@lines = split(/[\r\n]/, $message);
my @lines2;
s/(.{30})\s+/$1\n/g, push(@lines2, split(/\n/)) foreach @lines;
$lCnt=$#lines2+1;
$container = "/opt/httpd/root-wwwin/htd
$font = "/opt/httpd/root-wwwin/htd
$image = GD::Image->newFromJpeg($co
$lineStart=80;
$lineHeight=24;
$txtColor = $image->colorResolve(0,0,0
for $i (0..$lCnt){
$xPos = 390;
$yPos = $lineStart + ($lineHeight*$i);
@bounds = $image->stringTTF($txtColo
}
</code>
Thanks in advance for your help.
Regards,
seeker7806
Do you mean $message is input by user by typing in on keyboard and the script is not wrapping at the carriange returns entered by the user?
ASKER
yes. When the enter key is pressed in the text box the carriage return is not reflected on the image via the perl/cgi script although the perl/cgi script automatically wraps...
Thanks jmatix!
Thanks jmatix!
When I run the script standalone it is preserving the line breaks. It could be your server side script which processes the user input that strips all carriage returns.
ASKER
Thanks jmatix.
Actually the code above is the server side perl/cgi script. I am thinking that maybe my front end javascript is the problem?
I have a question pending on EE for the font end javascript.
It is wierd, because before, the previous code recognized carriage returns but not the wrap, and now it recognizes the wrap (via line splitting) but not the carriage return.
Regards,
seeker7806
Actually the code above is the server side perl/cgi script. I am thinking that maybe my front end javascript is the problem?
I have a question pending on EE for the font end javascript.
It is wierd, because before, the previous code recognized carriage returns but not the wrap, and now it recognizes the wrap (via line splitting) but not the carriage return.
Regards,
seeker7806
ASKER
There is an update. The perl cgi script appears to recognize hitting the return/enter button as one line break, but will not recognize hitting the return/enter button a second time for making a paragraph.
This is for both IE and Firefox.
On the front end regarding the javascript, hitting the carriage return works, but not in IE. In IE if you hit the carriage return, there are no line breaks or paragraphs in the preview image, but there are both line breaks and paragraphs on the image in Firefox.
In both cases however, when you hit the submit button, the result in the card being sent is just a line break but no paragraphs (when hitting the enter/return/carriage return button).
This is for both IE and Firefox.
On the front end regarding the javascript, hitting the carriage return works, but not in IE. In IE if you hit the carriage return, there are no line breaks or paragraphs in the preview image, but there are both line breaks and paragraphs on the image in Firefox.
In both cases however, when you hit the submit button, the result in the card being sent is just a line break but no paragraphs (when hitting the enter/return/carriage return button).
OK. Now I get it. That is how split() function in Perl behaves. To change that behavior modify the split() as below:
@lines = split(/[\r\n]+?/, $message);
@lines = split(/[\r\n]+?/, $message);
ASKER
Thanks jmatix.
This is still producing a <br> but does not recognize two carriage returns:
<code>
$text = $message;
@lines = split(/[\r\n]+?/, $message);
my @lines2;
s/(.{30})\s+/$1\n/g, push(@lines2, split(/\n/)) foreach @lines;
$lCnt=$#lines2+1;
</code>
Regards,
seeker7806
This is still producing a <br> but does not recognize two carriage returns:
<code>
$text = $message;
@lines = split(/[\r\n]+?/, $message);
my @lines2;
s/(.{30})\s+/$1\n/g, push(@lines2, split(/\n/)) foreach @lines;
$lCnt=$#lines2+1;
</code>
Regards,
seeker7806
Can you post the complete code as it is?
ASKER
<code>
#!/usr/local/bin/perl5
use CGI':standard';
use CGI::Carp qw/fatalsToBrowser/;
use GD;
use DBI;
use CommonSubs;
use arrData;
use dbInfo;
$q = new CGI;
$recId = time();
$userId = $ENV{'REMOTE_USER'};
$userInfo = &CommonSubs::DirInfo($user Id);
$from_sender = $q->param('from');
$to_recip = $q->param('to');
$cc_manager = $q->param('cc_manager');
$bcc = "xxxxxx\@xxxx.com";
$card = $q->param('card');
$message = $q->param('message');
my %availableCards = ("card1" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _1.jpg",
"card2" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _2.jpg",
"card3" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _3.jpg",
"card4" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _4.jpg",
"card5" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _5.jpg",
"card6" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _6.jpg",
"card7" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _7.jpg",
"card8" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _8.jpg",
"card9" => "/tech/performance-culture /rewards/e cards-mast er/images/ large_card _9.jpg");
my $cardToUse = $availableCards{$card};
my $emailContent = "";
$text = $message;
@lines = split(/[\r\n]+?/, $message);
my @lines2;
s/(.{30})\s+/$1\n/g, push(@lines2, split(/\n/)) foreach @lines;
$lCnt=$#lines2+1;
$container = "/opt/httpd/root-wwwin/htd ocs".$card ToUse;
$font = "/opt/httpd/root-wwwin/htd ocs/tech/p erformance -culture/r ewards/eca rds-master /templ/ver dana.ttf";
$image = GD::Image->newFromJpeg($co ntainer);
$lineStart=80;
$lineHeight=24;
$txtColor = $image->colorResolve(0,0,0 );
for $i (0..$lCnt){
$xPos = 390;
$yPos = $lineStart + ($lineHeight*$i);
@bounds = $image->stringTTF($txtColo r,$font,13 ,0,$xPos,$ yPos,$line s2[$i]);
}
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thur Fri Sat Sun);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
$dateandtime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
my $user=$user;
$ts = time();
$imgFile = "ecard_".$user."_".$ts.".j peg";
open(IMGFILE, ">/opt/httpd/root-wwwin/da ta-shared/ tech/artg/ cust-touch /videos/$i mgFile");
binmode IMGFILE;
print IMGFILE $image->jpeg;
close (IMGFILE);
$img = "<img border=0 src=\"http:\/\/wwwin-dev.xxxxx.com/data-shared/tech/artg/cust-touch/videos/$imgFile\" />";
($host, $db, $dbUid, $dbPwd) = &dbInfo::setDbInfo();
$errStr = "";
$dbh = DBI->connect("DBI:Oracle:( DESCRIPTIO N=(ADDRESS =(PROTOCOL =TCP)(HOST =$host)(PO RT=1521))( CONNECT_DA TA=(SID=$d b)))","$db Uid","$dbP wd");
$sql = qq/insert into CDO_ECARD(REC_ID,USERID,TO _RECIP,FRO M_SENDER,C C_MANAGER, CARD,MESSA GE,IMAGE,D ATEANDTIME ) values(?,?,?,?,?,?,?,?,?)/ ;
$sth = $dbh->prepare($sql) or $errStr .="SQL Prepare Error: $DBI::errstr<br />";
$sth->execute($recId,$user Id,$to_rec ip,$from_s ender,$cc_ manager,$c ard,$messa ge,$imgFil e,$dateand time) or $errStr .= "Execute Error: $DBI::errstr<br />";
$sth->finish or $errStr .= "Finish Error: $DBI::errstr<br />";
$dbh->commit or $errStr .= "Commit Error: $DBI::errstr<br />";
$dbh->disconnect;
$emailContent = <<HTML;
<p>
$img
</p>
<p><div style=\"font-family:arial, sans-serif ;font-size :16px;\"\> If you want to send an ecard click <a href=\"http:\/\/wwwin.xxxx.com\/tech\/performance-culture\/rewards\/ecards-master\/\"\>here\<\/a\><\/di v\><\/p\>
HTML
&CommonSubs::sendEmail("$t o_recip\@x xxx.com"," $from_send er\@xxxx.c om","You have received an e-card", "","$bcc",$emailContent);
print "Content-type: text/html\n\n";
print "<div style=\"font-weight:bold;f ont-size:1 8px;\"\>Yo ur ecard has been sent<\/div\>";
print "<p>";
print "$img";
print "<p>";
</code>
#!/usr/local/bin/perl5
use CGI':standard';
use CGI::Carp qw/fatalsToBrowser/;
use GD;
use DBI;
use CommonSubs;
use arrData;
use dbInfo;
$q = new CGI;
$recId = time();
$userId = $ENV{'REMOTE_USER'};
$userInfo = &CommonSubs::DirInfo($user
$from_sender = $q->param('from');
$to_recip = $q->param('to');
$cc_manager = $q->param('cc_manager');
$bcc = "xxxxxx\@xxxx.com";
$card = $q->param('card');
$message = $q->param('message');
my %availableCards = ("card1" => "/tech/performance-culture
"card2" => "/tech/performance-culture
"card3" => "/tech/performance-culture
"card4" => "/tech/performance-culture
"card5" => "/tech/performance-culture
"card6" => "/tech/performance-culture
"card7" => "/tech/performance-culture
"card8" => "/tech/performance-culture
"card9" => "/tech/performance-culture
my $cardToUse = $availableCards{$card};
my $emailContent = "";
$text = $message;
@lines = split(/[\r\n]+?/, $message);
my @lines2;
s/(.{30})\s+/$1\n/g, push(@lines2, split(/\n/)) foreach @lines;
$lCnt=$#lines2+1;
$container = "/opt/httpd/root-wwwin/htd
$font = "/opt/httpd/root-wwwin/htd
$image = GD::Image->newFromJpeg($co
$lineStart=80;
$lineHeight=24;
$txtColor = $image->colorResolve(0,0,0
for $i (0..$lCnt){
$xPos = 390;
$yPos = $lineStart + ($lineHeight*$i);
@bounds = $image->stringTTF($txtColo
}
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thur Fri Sat Sun);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
$dateandtime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
my $user=$user;
$ts = time();
$imgFile = "ecard_".$user."_".$ts.".j
open(IMGFILE, ">/opt/httpd/root-wwwin/da
binmode IMGFILE;
print IMGFILE $image->jpeg;
close (IMGFILE);
$img = "<img border=0 src=\"http:\/\/wwwin-dev.xxxxx.com/data-shared/tech/artg/cust-touch/videos/$imgFile\" />";
($host, $db, $dbUid, $dbPwd) = &dbInfo::setDbInfo();
$errStr = "";
$dbh = DBI->connect("DBI:Oracle:(
$sql = qq/insert into CDO_ECARD(REC_ID,USERID,TO
$sth = $dbh->prepare($sql) or $errStr .="SQL Prepare Error: $DBI::errstr<br />";
$sth->execute($recId,$user
$sth->finish or $errStr .= "Finish Error: $DBI::errstr<br />";
$dbh->commit or $errStr .= "Commit Error: $DBI::errstr<br />";
$dbh->disconnect;
$emailContent = <<HTML;
<p>
$img
</p>
<p><div style=\"font-family:arial,
HTML
&CommonSubs::sendEmail("$t
print "Content-type: text/html\n\n";
print "<div style=\"font-weight:bold;f
print "<p>";
print "$img";
print "<p>";
</code>
Try changing the split as follows to inlcude the line breaks:
$text = $message;
@lines = split(/([\r\n])/, $message);
my @lines2;
s/(.{30})\s+/$1\n/g, push(@lines2, split(/(\n)/)) foreach @lines;
$lCnt=$#lines2+1;
$text = $message;
@lines = split(/([\r\n])/, $message);
my @lines2;
s/(.{30})\s+/$1\n/g, push(@lines2, split(/(\n)/)) foreach @lines;
$lCnt=$#lines2+1;
ASKER
Thanks jmatix.
I received the following error message:
Software error:
syntax error at /opt/httpd/root-wwwin/pcgi -bin/tech/ performanc e-culture/ ecards/add MsgToCard. cgi line 54, near ")) "
Execution of /opt/httpd/root-wwwin/pcgi -bin/tech/ performanc e-culture/ ecards/add MsgToCard. cgi aborted due to compilation errors.
line 54:
<code>
s/(.{30})\s+/$1\n/g, push@lines2, split(/(\n)/)) foreach @lines;
</code>
I received the following error message:
Software error:
syntax error at /opt/httpd/root-wwwin/pcgi
Execution of /opt/httpd/root-wwwin/pcgi
line 54:
<code>
s/(.{30})\s+/$1\n/g, push@lines2, split(/(\n)/)) foreach @lines;
</code>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks jmatix:
Now the solution inputs too many carriage returns! But it seems we are making progress from before!
I am attaching a jpeg of the screen shot.
Regards,
seeker7806
ecard-test1.jpg
Now the solution inputs too many carriage returns! But it seems we are making progress from before!
I am attaching a jpeg of the screen shot.
Regards,
seeker7806
ecard-test1.jpg
ASKER
Hey jmatix:
I monkeyed around with the script and got it to approximate a proper carriage return. It's not perfect but I am hoping it will do for the stakeholder.
Thanks again
I monkeyed around with the script and got it to approximate a proper carriage return. It's not perfect but I am hoping it will do for the stakeholder.
Thanks again