Jump to content

Emoticon function problem *solved*


GuitarGod

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]
Link to comment
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]
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.