Jump to content

Archived

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

GuitarGod

Emoticon function problem *solved*

Recommended Posts

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:

[code]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[/code]

Share this post


Link to post
Share on other sites
I'm sure $code[] = $qry[code]; 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[/code]

Share this post


Link to post
Share on other sites

×

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.