PDA

View Full Version : smilies with php and mysql


Alex
January 5th, 2005, 13:18
I want to replace the smilie code with the HTML img tag in the POSTed text. I have a MySql table that holds all the codes and the HTML.
eg: :) should go to <img src="..." alt="" />
Heres what I have:

[syntax:07e593ee34="php"]
$getsmile = mysql_query("SELECT * FROM ".$so_prefix."_smilies") or die("Sql error >>>" . mysql_error());

while($smilies = mysql_fetch_array($getsmile)) {

if(preg_match('/$smilies[code]/', $cleancomm)) {
$fincomm = str_replace('$smilies[code]', '$smilies[smilie]', $cleancomm);
}
}
[/syntax:07e593ee34]

This doesn't find any matches if '$cleancomm' contains a value from the 'code' table row...
Any ideas?
Is there a better way to search and replace the smilie code with the actual image?

[b]Edited for proper BBCode, the_pm