I'm looking for a small PHP script to do a search and replace in a text file. What the script should do is this:
Open text file containing several paragraphs of text (we'll call it the story file) and replace certain words. Those words will be determined by the contents of another file (we'll call it the words file).
The file containing the list of words to be replaced will be in the following format:
car|vehicle|automobile|ride|wheels|auto
soda|pop|coke|soft drink
dog|canine|puppy|mutt|fido
stove|oven|range
run|dash|sprint|jog|rush|dart
Now lets say our text file contains the following sentence:
"The puppy had to run to get away from the automobile."
The script should open the words file and RANDOMLY replace the words puppy, run and automobile with another word from the same line. The script should ONLY match entire words. For example we might end up with any of the following:
"The dog had to rush to get away from the vehicle."
"The mutt had to dash to get away from the car."
The story file may contain several paragraphs of text. 8-10 paragraphs would be relatively common. The words file may end up containing well over 1000 lines each with 3-6 synonyms. As such, this script will need to be as fast as possible.