I have a string which contains several keywords in square backets which I want to identify, extract, and replace with something else:
For example:
‘You will win [winnings] or [slice].’
I want to identify all the terms within the squares, take those terms and replace them with certain values.
So it should end up like this:
‘You will win 100 or 95%.’
Any ideas?
Note that this will completely fall apart if you have unbalanced brackets (i.e.
[[foo])For PHP versions less than 5.3: