Lets say I have a large text file and I have a certain string like
And I want to find this string in the text file(the actual string I'm referring to goes on two lines) and then I want to replace say save with !save if a condition is true but only within this string in the file. There are other places within the file that have 'save' but I don't want to touch them. After replacing save with !save in that string, I want to write the new file over the old file. So how do I do this. Every time I've tried, it replaces every instance of save with !save in the file and not just the instances within the string which is what I want.
Basically I'm asking how to use the limit parameter in preg_replace to replace the last instance of "save" with "!save" , since there are about 6 instances on the page.