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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.