ScoreKeeper Posted February 8, 2011 Share Posted February 8, 2011 Right, First time on this site but hopefully I can figure out what im doing wrong. I am currently making a real time chat database for my website and have been having an issue with the coverting of string to emote image links. function Smiley($texttoreplace) { $smilies=array( '' => "<img src='images/emotes/smile.gif'/>", '' => "<img src='images/emotes/sad.gif'/>", '' =>"<img src='images/emotes/angry.gif'/>", ''=> "<img src='images/emotes/shocked.gif'/>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace=strtr($texttoreplace, array_keys($smilies)); return $texttoreplace; } I Have even tried $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); but that didnt seem to work either. Here is my full code. <?php include "connect.php"; $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("Yay, Jump off cliff"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>21) { $startrow=$getmessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); while($getmsg3=mysql_fetch_array($getmsg2)) { $message=Smiley($message);//should make smiley here but not working....hmmmm print "<font color='red'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } function Smiley($texttoreplace) { $smilies=array( '' => "<img src='images/smile.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; } //this is my refresh script below ?> <script> setTimeout("window.location.replace('chatlog.php')",4000); </script> Any help would be great, been looking at this code for a while now so some fresh eyes would be great. Thanks, Score Quote Link to comment Share on other sites More sharing options...
btherl Posted February 8, 2011 Share Posted February 8, 2011 The problem is here: $message=Smiley($message);//should make smiley here but not working....hmmmm print "<font color='red'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; Your Smiley() function works, but you are applying it to $message, then you are displaying $getmsg3['message'] instead. Try: $message=Smiley($getmsg3['message']);//should make smiley here but not working....hmmmm print "<font color='red'><b>$getmsg3[name]:</b></font> $message<br>"; Quote Link to comment Share on other sites More sharing options...
ScoreKeeper Posted February 8, 2011 Author Share Posted February 8, 2011 It doesnt seem to worh though. even when i apply my owndummy string to input to the function, it does not convert it. Also tried $message=Smiley($getmsg3['message']);//should make smiley here but not working....hmmmm print "<font color='red'><b>$getmsg3[name]:</b></font> $message<br>"; i noticed that already and changed that. It still doesnt even seem to work. Smiley('') doesnt work. Quote Link to comment Share on other sites More sharing options...
btherl Posted February 8, 2011 Share Posted February 8, 2011 I copied and pasted your Smiley() function from the second section of code in your first post. That version works. Make sure you are using this version: function Smiley($texttoreplace) { $smilies=array( '' => "<img src='images/smile.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; } Quote Link to comment Share on other sites More sharing options...
ScoreKeeper Posted February 8, 2011 Author Share Posted February 8, 2011 Yeah, that works..... I went through my code and realised some stupid stuff in it. but it works now. so thanks. 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.