/me realises that it should be:
for($number_of_a_tags - $number_of_close_a_tags){
print '</a>'
}
above. But you get the idea.
Do you have problems, concerns or recommendations about the technical side of the Phoenix? Air them here. Compliments also welcome.
/me realises that it should be:
for($number_of_a_tags - $number_of_close_a_tags){
print '</a>'
}
above. But you get the idea.
Exactly.
The brute count doesn't respect the order, and you will risk putting out invalid html if they let two tags slip.
A stack, OTOH, will address some of that.
you will risk putting out invalid html if they let two tags slip.
Well yeah, but we've already got invalid HTML or we wouldn't be doing it.
A stack, OTOH, will address some of that.
So how do you envisage it working?
I'm just not seeing it in my mind.
Every tag gets pushed onto the end of an array, and then popped off it by the appearance of a closing tag?
Like, we encounter a FONT tag, the array becomes
FONT
then we encounter a bold tag, and the array is now
FONT,B
but then we encounter the close-B tag and dump the B, and we're back to:
FONT
and then when we get to the end of the post, if there's anything left in the array, that's what needs closing?
What happens if someone accidentally posts this then:
<FONT> blah blah blah <B> blah blah </FONT> blah blah </B>
because they match, but not in the right order.
I got some debugging to do, true, but if WX can output them in order, so can we. I'm just not going to have energy to logic it before tomorrow.
if WX can output them in order, so can we
That's the spirit!
What if we recorded the tags according to their position in the string?
blah blah blah <FONT>
would be stored in a hash with a key of 16 (because it starts at char 16) and a value of FONT.
Then all we need to do is see if there's a close-font with a greater number as its key.
Or! Or! Or!
We pop on opening tags. We delete (push or whatever) them when we encounter a closing tag. Then we close what's left in reverse order.
But I have to look up array searching.
We pop on opening tags. We delete (push or whatever) them when we encounter a closing tag.
How does that work for crossed-over tags, that's my question, like before.
Because we're not popping to remove. We're just deleting the incident nearer the end. We don't close until the end.
So if we have:
<i>italicky <b>bold like </i>
The process will look like:
Sound sound?
edit: Ironically, I forgot to close my <ol>
Sound sound?
Pretty much. What if there's more than one of each tag in the array? Which one gets deleted?