Right now I am using this function for emoticons:
function emoticons($text) {
$icons = array(
\':)\' => \'
You can use the preg_replace function and then use word boundaries in the regular expression.
foreach($icons as $icon=>$image) {
$icon = preg_quote($icon);
$text = preg_replace("~\b$icon\b~",$image,$text);
}
You need to use word boundaries and not white space because this will take care of the start and end points to. Needing a space before means that just a :) won't be found.