Errore funzione per form

gasparroa

Utente Attivo
4 Dic 2008
57
0
0
Ho usato questa funzione per convertire ":-D",":-)",":-("

il problema e che quando in una stringa ho due volte ":-):-)" me ne converte una sola come mai?

function faccine($testo){
$msg1 = str_replace(":-D", "<img src='smile/smile_2.gif'>", $testo);
$msg2 = str_replace(":-)", "<img src='smile/smile_1.gif'>", $testo);
$msg3 = str_replace(":-(", "<img src='smile/smile_3.gif'>", $testo);
return $msg=$msg1.$msg2.$msg3;
}
 
Prova così:

PHP:
function faccine($testo){
	$testo = str_replace(":-D", "<img src='smile.jpg'>", $testo);
	$testo = str_replace(":-)", "<img src='smile.jpg'>", $testo);
	$testo = str_replace(":-(", "<img src='smile.jpg'>", $testo);
	return $testo;
}
 

Discussioni simili