Jump to content

Building Chat Database ouput but not parsing properly. Need help.


ScoreKeeper

Recommended Posts

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

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>";

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.

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;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.