View Full Version : Replacing ;) with images
ACJavascript
06-30-2002, 07:12 PM
Hi everyone,
Okay well heres the gig,
I want to replace ;) for a smily.
I pretty sure that the replace syntax is this
s/whatitslookingfor/replaceitwiththis/;
But i get an error when i do this
s/;)/http://www.acjavascripts.com/Images/hippy.gif/;
So i though it the error was with the http:// //
so i did this
s/;)/http:\/\/www.acjavascripts.com\/Images\/hippy.gif/;
but it still errors please can someone help me out:(:(
Thankxxxx in advance :D
Calilo
06-30-2002, 10:06 PM
you also need to escape the ) and the ;
$input =~ s/;\)/http:\/\/www.yourdomain.com\/smilies\/happy.gif/g;
calilo
ACJavascript
06-30-2002, 10:31 PM
Calilo thanks alot for your reply,
I'm not getting the error anymore :D
But it doesn't replace it. So this is how i have it setup and mabye you can see where i'm goin wrong:D
1) The person clicks the sign my guestbook link.
2) The go to a html page the type in textboxs name,email,comments ect.
3) the click sumbit,
4) it sends the info to a cgi wich write the data to a database. .dat.
5) it then redirects the user back to the guestbook, and the guestbook reads the data file and prints it out onto the page.
The Guestbook.cgi is where i have the s/;)// replace thingy.
http://www.acjavascripts.com/cgi-bin/Guestbook/Guestbook.cgi
Thats the guestbook link check it out it ya like.
Would it be easire for me to just post my cgi code??
chrisvmarle
06-30-2002, 11:22 PM
Maybe you can send the sourcecode, so we see what went wrong.
Did you use the s/;\)/http:\/\/www.yourdomain.com\/smilies\/happy.gif/g; on the variable contaning the text the user types?
BTW, I would use this:
$users_text =~ s/\;\)/\<img src=\"http:\/\/www\.yourdomain\.com\/smilies\/happy\.gif\"\>/g;
What is does:
It replaces the ";)" with an image.
I used \. instead of . because . also means "any character".
Mzzl, Chris
ACJavascript
06-30-2002, 11:31 PM
Okay this what i have so far.
--------------
Guestbook.cgi
This is what the user sees
-------------
#!/usr/bin/perl
print "Content-type:text/html\n\n";
#The Guestbooks backgroundColor
$bgColor = "navy";
#The Guestbooks FontColor
$fontColor = "gold";
#The Name of your Guestbook
$guestbookName = "www.ACJavascripts.com's Guestbook!";
#The Sign Guestbook link's Text
$sign = "Sign My Guestbook";
#Location of WrittingMessage.html
#Example: http://www.yoursite.com/WriteMessage.html
$writeMessage = "http://www.acjavascripts.com/WriteMessage.html";
#hrColor, The Line color that seperates the messages
$hrColor = "lawngreen";
open(INF,"MessageDatabase.dat");
@msg = <INF>;
close(INF);
print "<html><head><title>$guestbookName</title></head>\n";
print "<body bgColor=\"$bgColor\">\n";
print "<BR><center><h2>$guestbookName</h2>\n";
print "<b><a href='$writeMessage'>Sign Guestbook</a><br><br></center>\n";
foreach $KK (@msg){
chomp($KK);
($Email,$Name,$Loc,$message) = split(/\|/,$KK);
$KK=~ s/\;\)/<img src\"http:\/\/www\.acjavascripts\.com\/Images\/happy.gif\">/g;
print "<table><tr><td><b><font color='$fontColor'>Name: $Name</font></b></td></tr><tr><td>\n";
print "<b><font color='$fontColor'>Email: $Email</font></b></td></tr><tr><td>\n";
print "<b><font color='$fontColor'>Location: $Loc</font></b></td></tr><tr><td>\n";
print "<b><font color='$fontColor'>Message: $message</font></b></td></tr></table>\n";
print "<br><hr color='$hrColor'><br>\n";
}
print "<center><sup><h5>Guestbook By www.ACJavascripts.com/CGI/AC-CGI.html</h5></sup><BR><BR>\n";
print "</body></html>";
---------------------------------
This is the WriteMessage.html
----------------------------------
<html>
<head>
<title>Guestbook</title>
</head>
<body>
<center>Write To ACJavascripts Guestbook</center>
<hr>
<form action="http://www.acjavascripts.com/cgi-bin/Guestbook/WriteMessage2.cgi" method="POST">
<table>
<tr>
<td>
Email </td><td><input type="text" name="Email">
</td></tr><tr><td>
Name </td><td><input type="text" name="Name">
</td></tr><tr><td>
Location </td><td><input type="text" name="Loc">
</td></tr><tr><td>
Message </td><td><textarea name="message" rows=8 cols=60 wrap="virtual">
</textarea>
</td></tr></table>
<input type="submit" value=" - Submit - ">
</form>
</body>
</html>
---------------------------
This is the WriteMessage.cgi
----------------------------
#!/usr/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($name, $value) = split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][-a-fA-F0-9])/pack("C",hex($1))/eg;
$value =~ s/\n/ /;
$value =~ s/\r//g;
$value =~ s/\cM//g;
$FORM{$name} = $value;
}
$Refresh = "http://www.acjavascripts.com/cgi-bin/Guestbook/Guestbook.cgi";
open(OUTF,">>MessageDatabase.dat");
flock(OUTF,2);
seek(OUTF,0,2);
print OUTF "$FORM{'Email'}|$FORM{'Name'}|$FORM{'Loc'}|$FORM{'message'}\n";
close(OUTF);
print "Content-type:text/html\n\n";
print "<html><head><title>Thank you</title><META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=$Refresh\"></head>\n";
print "<body>\n";
print "<BR><BR><BR><BR><BR><BR><center>\n";
print "<table border=1 borderColor=\"black\">\n";
print "<tr><td bgColor=\"salmon\">\n";
print "<font color=\"black\"><b><center>\n";
print "Thank you for posting your message.<BR>\n";
print "You will be redirected shortly.<BR><BR>\n";
print "<h4>If you browser does not redirected you then click here: <a href=\"$Refresh\">Guestbook</a>\n";
print "</body></html>";
------------------------------
Thats Pretty Much that. lol
I just saw this. Where i have the $value=~ s/\n//g;
is that were i should put the smily replace ??
ACJavascript
07-01-2002, 02:19 AM
Thanks everyone for your great help.
That thing i was thinking of - placing the s/s/s/g; (replace syntax)
width the $value=~ s/s/s/g;
It works great now, Thanks alot for all your help!:D:D:D:D:D:D:D
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.