I have some text that ends with a [br] tag, optionally followed by more [br] tags and/or whitespace characters, but nothing else. For example:
bla blah d [br] fkjd fkdh fkd fks
sdkf skdfh djfh[br]
[br]
[br]
I would like to insert text before that [br] tag, like this:
bla blah d [br] fkjd fkdh fkd fks
sdkf skdfh djfh [INSERTED TEXT][br]
[br]
[br]
My problem is, I don’t know how many additional [br] tags or whitespace characters there will be.
Is there an easy way to do this in PHP?
What about something with preg_replace?
The regex is looking for a
[br]tag, followed optionally by some amount of whitespace, and further[br]tags. There can be any number of following[br]tags. The i at the end indicates case insensitivity.You can view this running on codepad