I want PHP to loop, line by line, through a big 100MB text file, and append the phrase "Good Quality!" to any line with the word "car" in it. Here's an example (the first 4 lines of a 500,000-line text file):
Original file:
Brand new motor boat.
Used gold colored car.
Bag of sweet candy.
Shiny car with windows.
What I want:
Brand new motor boat.
Used gold colored car. Good Quality!
Bag of sweet candy.
Shiny car with windows. Good Quality!
I experimented with FOPEN and FWRITE, as well as using foreach(preg_split("/((\r?\n)|(\r\n?))/",$big_file) as $line with the "file_get_contents/file_put_contents" functions and no matter what I tried or did, I couldn't get anything to work. For some reason, I can't wrap my head around making PHP loop through a file line by line and making changes only to certain lines.
Thank you in advance!