I think you're going to need regular expressions for this. Unfortunately, my regex writer is off today. π π π
This code will do it, as long as there are no spaces between the smilies:
// This line is just to make the next two simpler:
$comment = str_replace('<img src="images/smilies/smile.gif" border="0" alt="">',
'[smile here]', $comment);
while (strpos($comment, '[smile here][smile here]') !== false) {
$comment = str_replace('[smile here][smile here]', '[smile here]', $comment);
}
$comment = str_replace('[smile here]', ' <img src="smilies/smile.gif">', $comment);
With irregular spaces between some of the smilies it becomes more complicated.
Edit: I just saw wilku's reply; I'd go with his solution.