I my application I have custom tags that contains other tags. Example:
I have a tag named {BIG} that can contain text and subtags like {BIG2} text {/BIG2}
A {BIG2} parent can be only an {BIG} tag a {BIG3} parent should be a {BIG3}.
I hope it makes sense.
My current approach is to iterate the whole text and check for the { character and make sense if its the opening or closing tag.
for ( $i = 0; $i < strlen( $this->input ); $i++ ) {
$char = $this->input[$i];
if ($char == '{') {
if ($this->input[$i + 1] == '/') {
// close tag
echo 'close tag on pos: ' . ($i + 1);
} else {
// open tag
}
}
}
My problem is this approach seems very fragile and laborious and I was wondering if I am on correct curse?
I don't the solution because I am doing this as an exercise. I just want to know that this is the correct approach to solve the problem.