Use the ereg_replace() function (read the manual), or you can also preg_replace() and str_replace().
Example:
<?
$str ="Hello all : ) " ;
$icon = "/path/to/icon/icon.gif";
echo ereg_replace (": )", "<img src=$icon border=0>", $str);
?>
It will replace the ": )" with <img> html tag....
PS: I'm forced to put space between : and )
hope it helps! 🙂