twilitegxa Posted July 19, 2009 Share Posted July 19, 2009 Is there a way to display the smiley face images instead of the symbols for the images that display in my chat window? Right now it is set to display when the user clicks the smile smiley face. Here is the page: <?php session_start(); ?> <html> <head> <title></title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <?php include "connect.php"; if(isset($_POST['submit'])) //if submit button push has been detected { $message=$_POST['message']; $name=$_SESSION['userName']; if(strlen($message)<1) { print "You did not input a message"; } else if(strlen($name)<1) { print "You are not logged in. Please log in."; } else { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "Your IP is banned from posting. Please contact administration."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$name','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } print "<form action='submit.php' method='post' name='form'>"; //print "<strong>Your name:</strong><br>"; not needed //print "<input type='text' name='name' size='20'><br>"; not needed print "<strong>Your message:</strong><br>"; print "<textarea name='message' cols='40' rows='4'></textarea><br>"; print "<a onClick=\"addSmiley('')\"><img src='images/smile.gif'></a> "; //replace images/smile.gif with the relative path of your smiley print "<a onClick=\"addSmiley('')\"><img src='images/sad.gif'></a> "; print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> "; print "<input type='submit' name='submit' value='submit'></form>"; print "<script language=\"Java Script\" type=\"text/javascript\">\n"; print "function addSmiley(textToAdd)\n"; print "{\n"; print "document.form.message.value += textToAdd;"; print "document.form.message.focus();\n"; print "}\n"; print "</script>\n"; print "<br><br>"; ?> </body> </html> And I think you might need this one as well: <html> <head> <title></title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <?php include "connect.php"; $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>10000000) { $startrow=$getmessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime DESC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); while($getmsg3=mysql_fetch_array($getmsg2)) { $message=' '; $message=Smiley($message); //Smiley faces print "<font color='teal'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } function Smiley($texttoreplace) { $smilies=array( '' => "<img src='images/smile.gif'>", ':blush' =>"<img src='images/blush.gif'>", ':angry' =>"<img src='images/angry.gif'>", ''=> "<img src='images/shocked.gif'>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); return $texttoreplace; } ?> <script> setTimeout("window.location.replace('chatlog.php')",1000); </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 You will have to do $getmsg3['message'] = Smiley($getmsg3['message']); Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 19, 2009 Author Share Posted July 19, 2009 That didn't work. Maybe I can't do it the way my script is right now. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 You have this: while($getmsg3=mysql_fetch_array($getmsg2)) { $message=' '; $message=Smiley($message); //Smiley faces print "<font color='teal'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } It should be: while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = Smiley($getmsg3['message']); print "<font color='teal'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 19, 2009 Author Share Posted July 19, 2009 This code only worked for the first smiley. How do I get the others to work as well? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 What do you mean with "it doesn't work"? function Smiley($texttoreplace) { $smilies=array( '' => "<img src='images/smile.gif'>", ':blush' =>"<img src='images/blush.gif'>", ':angry' =>"<img src='images/angry.gif'>", ''=> "<img src='images/shocked.gif'>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace = str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); return $texttoreplace; } echo Smiley('foo bar '); Outputs: foo <img src='images/smile.gif'> bar <img src='images/shocked.gif'> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.