since the text I get when I go to edit is exactly what I typed
Well, you might go back to edit it to correct the open tags... or is that circular logic?
And they closed them in order ...
Damn, that's actually smart!
How are we to keep up the sense of "we're smarter than WX" if the connection's going to keep dropping and they actually do have pockets of good code?
So grab all the tags from the string, and push them into an array, then grab all the closing tags from the string, and push them into an array... hmmm. I really don't know what's the best way to do it. Theoretically trivial, but some questions about the implementation, I guess...
OK thinking about it in the shower, I see I was over-reacting before. In my defense it's early here and I've only had the one coffee.
The task is relatively simple, because we don't have to parse lots of code, only the post itself, and because relatively few HTML tags are allowed anyway.
So,
after
strip_tags() happens, then we would count all the tags that are still there and note their position (optional, because if you've made a mistake you've made a mistake, and who knows what you intended, but you shouldn't be making other people's posts go wrong).
Showers are good.
How about we pop them on a stack, and pop them back off again? I have not yet thought deeply about how you code around people that close in the wrong order ...
How about we pop them on a stack, and pop them back off again?
That makes sense. Though doing it by brute calculation would probably do just as well, what with the not-knowing-what-people-intended thing.
like:
if($number_of_a_tags > $number_of_close_a_tags){
print '</a>'}
kind of thing.
In netscape they stayed pink until the new page.
And yes, I think a brute count will work fine. (Needed on post only).
If there are is one fewer end pre than pre, you add an end pre to end of the post -ditto with bolds, italics table and so forth. Don't worry if it screws up the person's post. They can edit it if they wish. So long as it does not screw up the next persons post. So that really is a single additional pass once tag stripping is done.
We are not corecting all possible problems - just some simple ones where other peoples post can be hurt.
/me realises that it should be:
for($number_of_a_tags - $number_of_close_a_tags){
print '</a>'
}
above. But you get the idea.
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.