This'll never work. Consider this:
$message = "HI :))";
You run your loop, and iterate through all the options. First up is :)
, so $message becomes:
HI <img src="s1.gif" class="post_smiley alt=":)" title=":) etc...>)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- originally :)
^--- leftover )
Now you come to :))
and it doesn't exist in your string anymore.
Going the other way, replacing :))
first, then :)
is even worse. You'll end up with
HI <img src="s33.gif" .... alt="<img src="s1.gif" .... alt=":)" >>
^^^^^---oops. img tag INSIDE another img tag.
You cannot do blind string replacements like this, where some of the replacement strings are subsets of other strings. You'll end up nesting replacements inside replacements inside replacements etc... and just end up with a huge incredibly broken pile of bad html.