Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Replacing words in a string
- Warren Oates
November 20, 2004, 2:05 pm
rate this thread
for instance, and I get them into an array, how then can I replace those
words in a string with something else:
"The quick dog took viagra and the lazy cat was unhappy."
I want it to say:
"The quick ### took ### and the lazy ### was unhappy."
I've been banging my head against this, with foreach (both forms) and
rtrim, and preg_replace, and str_replace, and I can't get it to replace.
I don't need to see code, just a general "algorithm" would be useful.
Looks like more of Texas to me.
.... Arizona, where the nights are warm and the roads are straight.
Re: Replacing words in a string
Sorry, but you really do not need an algorithm:
str_replace() can take an array for a parameter.
$x = str_replace(
array("dog", "cat", "viagra"),
"The quick dog took viagra and the lazy cat was unhappy.");
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com /
== ** ## !! !! ## ** ==
bypass the spam filter. I will answer all pertinent mails from a valid address.
- » checking room availability for hotel booking system
- — Previous thread in » PHP Scripting Forum