I need to replace a huge amount of words and phrases in long strings, words and phrases might repeat several times.
I have successfully built a preg_replace()
arrays and it works nearly well. The only problem is that the list of words and phrases to replace I want to have is overlapping, for example:
"acid" ---> "replacement1"
"light acid" --> "replacement2"
and it makes preg_replace
to complain, as "acid" is in both, which is not surprising.
The question: How to build a proper function to replace words and phrases like in my scenario?