Jump to content


Photo

Emoticon function problem *solved*


  • Please log in to reply
1 reply to this topic

#1 GuitarGod

GuitarGod
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 01 October 2006 - 10:17 AM

Hey all,

OK, i have a database containing a smilie id, smilie URL and smilie code. I have created a function which will replace the code with the smilies, but for some reason it's not working:

function smilie( $msg )
{
  $sql = "SELECT * FROM `smilies`";
  $result = mysql_query($sql);

  while ($qry = mysql_fetch_array($result))
  {
    $code[] = $qry[code];
    $img[] = "<img src=\"$qry[image_url]\">;
  }

  $message = preg_replace($code, $img, $msg);
  return $message;
}[/code]

I try this, but the code still appears instead of the smilie, can anyone help?

[b]EDIT:[/b] Ok, i did a bit of 're-jigging' with the code and it works now


#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 01 October 2006 - 10:25 AM

I'm sure $code[] = $qry
; would normaly bringup an error because u need $code[] = $qry['code'];

give this a try

[code]function smilie( $msg )
{
  $sql = "SELECT * FROM `smilies`";
  $result = mysql_query($sql);
  $code = array();
  $img = array();
  while ($qry = mysql_fetch_array($result))
  {
    $code[] = $qry['code'];
    $img[] = "<img src=\"$qry[image_url]\">;
  }

  $message = str_replace($img, $code, $msg);
  return $message;
}[/code]

I'm taking it that $code is the html and $img is stuff like [smiley]

Regards
Liam

www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users