Good day all,
I have a preset situation that can’t be changed, that revolves around a portion of html text (the body of a page), and some user configurable tags inside this body.
The problem, which is very template-like but that’s related to a non-refactorable source situation, is that I need to split the original body into
html part 1
tag1
html part 2
tag2
html part 3
tag3
and so on, taken for example from
<body>
<b>This is my first line</b> And this is <b>%%tag one%%</b> but of course it
doesn't end here %%second tag%%
Additionally %%second tag%% tags can be repeated inside the body.
In fact, %%tag one%% or even %%tagthree%%
</body>
Ideally, I should obtain an array:
[0] = "<body>
<b>This is my first line</b> And this is <b>"
[1] = "%%tag one%%"
[2] = "</b> but of course it
doesn't end here "
[3] = "%%second tag%%"
[4] = "Additionally "
[5] = "%%second tag%%"
[6] = " tags can be repeated inside the body.
In fact, "
[7] = "%%tag one%%"
[8] = " or even "
[9] = "%%tagthree%%"
[10] = "
</body>"
Tags are simple text labels (allow space, _ and -) enclosed by %%, for example %%first tag%%
I realize there’s a lot of different solutions, but since I have a need for the highest possible performance, I am in need of directions for what to try and what to avoid. Additionally, I’m wondering if php already has some function for this kind of case.
Hopefully some of you have already faced something like this, which is a bit too much to solve ideally, for my current parsing skills.
Thanks
A dumb way: