GuitarGod Posted October 1, 2006 Share Posted October 1, 2006 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] Quote Link to comment Share on other sites More sharing options...
shocker-z Posted October 1, 2006 Share Posted October 1, 2006 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]RegardsLiam[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.