Please help I want to use str_replace PHP: for $find[] = '1'; $find[] = '2'; $find[] = '3'; $find[] = '4'; $find[] = '5'; $replace[] = 'audio'; $replace[] = 'video'; $replace[] = 'document'; $replace[] = 'program'; $replace[] = 'others'; PHP: on [type] PHP: in echo "<td align=left bgcolor=$bgcolor id='title'><font face='Verdana' size='2'>$noticia[type]</font></td>"; PHP:
Below is a scheme that might work for you (you can also read about str_replace here): $text = '...'; $text = str_replace("1", "audio", $text); $text = str_replace("2", "video", $text); $text = str_replace("3", "document", $text); $text = str_replace("4", "document", $text); $text = str_replace("5", "document", $text); echo $text; PHP:
No need to call the function multiple times. Baris can use his arrays. $text = str_replace($find, $replace, $text); PHP:
But I do not know how to use $text = str_replace($find, $replace, $text); PHP: on echo "<td align=left bgcolor=$bgcolor id='title'><font face='Verdana' size='2'>$noticia[type]</font></td>"; PHP: I used str_replace on another page. It worked. The code was echo "<td>" . str_replace($find, $replace, $row['type']) . "</td>"; PHP: I want to do same thing here echo "<td align=left bgcolor=$bgcolor id='title'><font face='Verdana' size='2'>$noticia[type]</font></td>"; PHP: But I do not know how to do.
echo "<td align=left bgcolor=$bgcolor id='title'><font face='Verdana' size='2'>".str_replace($find, $replace, $noticia['type'])."</font></td>"; PHP: It should work for you.
I see you want to replace numbers with words? Where do there numbers come from? The database row? If $noticia[type] is only a number (1 to 5), I'd do something like this. $replace = array( 1 => "audio", 2 => "video", 3 => "document", 4 => "document", 5 => "document" ); echo " [snip] <font face='Verdana' size='2'>". $replace[$noticia['type']] ."</font> [snip]"; PHP: