Ah, no olvides que esto se hace AL LEER el mensaje Y NUNCA AL ENVIARLO.
Si lo quieres hacer en forma de función...
Código PHP:
function mostrar_caritas($texto) {
$texto = str_replace (":)", "<img src='carita_feliz.gif'>", $texto);
$texto = str_replace (":(", "<img src='carita_triste.gif'>", $texto);
$texto = str_replace (":O", "<img src='carita_sorprendido.gif'>", $texto);
return $texto;
}
echo mostrar_caritas($texto);
Suerte