This first example is simple...
In the str_replace() function, you have 3 terms. the first, %body%, is the term or terms that you want replaced. The second, black, is what you want to replace the first term with. The third is the code where you want the string replacement to occur...
Code:
<?php
// Provides: <body text='black'>
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
?>
Next, using the array() function, we can choose multiple terms to be replaced. Therefore, with $vowels as the first term, you will replacing everything in the array (all the vowels). Leaving the second term blank (still quotations, but no space between) will cause no replacement in the third term, Hello World of PHP. Vowels will be removed and it will now be: Hll Wrld f PHP. Note, just in case, that everything in the array is being replaced by the same thing.
Code:
<?php
// Provides: Hll Wrld f PHP
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
?>
Like the example above, we are replacing multiple terms in an array. This time, however, we have a second array which contains the three
different words we want to replace the old words. All arrays are respective, so fruits is replaced with pizza, vegitables with beer, and fiber with ice cream. $newphrase then creates the new sentence with the str_replace function. Note that when using a variable in the str_replace function, no quotation marks are used.
Code:
<?php
// Provides: You should eat pizza, beer, and ice cream every day
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
?>
I hope that helps.
Code taken from [url=http://us4.php.net/manual/en/function.str-replace.php:alkwxme6]php.net[/url:alkwxme6].
Descriptions and explanations by me.
Headnerd, you can grab this if you want for your site.