Is there such a thing as closing all tags using HTML/javascript only? I know it can be done in php using the html purifier, for instance, but a php solution is out of question right now. What I need is a code I can place at the end of the posts that will prevent affecting the rest of the site if there are unclosed HTML tags within those posts. The posts may contain all kinds of unclosed HTML tags. From none to a dozen.
Why not just make sure you have valid code in the first place? Though if this is user posts, that's one of the many reasons bbcode exists; you use regex to match the bbcode and turn it into markup -- if a closing bbcode tag is missing, it doesn't get converted.
And I do some of it, but there comes a point that no regex will be able to help. For instance, somebody posted something like this recently: <div style="text-align: center;"> <font size=4> <font size=4> It's<br>Some text <br> <br>Some text <br> <br>Some text <br> <br>Many Some text <br> <br>Some text <br> <br> <br> <br> <a href="http:// somelink.com "> <span style="color: rgb(255, 0, 0); text-decoration: underline;"> Some text<br>Some text </span> </a> <br> <br> <br> <br> <img style="max-width:100%; height:auto;" style="width: 1087px; height: 559px;" alt="bear hunter sticker" src=" http:// someimage.com/1.JPG "> <br> <br> <span style="text-decoration: underline;"> <span style="text-decoration: underline;"> </span> </span> </font> </font> <a href=" http:// somelink.com "> <big style="text-decoration: underline;"> <font size=4> <font size=4> <font size=4> </font> </font> </font> </font> </a> <br> <br> <br> <br> </div> <p></p> Code (markup): As you can see it's a complete mess. On one hand I'd love to make sure that only valid codes are entered, on the other hand when money is involved I want people to enter whatever they want since they are paying for it. So, I just wish I could somehow close all unclosed tags and forget about it.
Ok, what/how are they "posting"? Honestly, if they are writing THAT for HTML what *****ing business do they have posting jack ****? That's a case of where I'd tell that person they're not allowed to post until they get a plowing clue, or just walk away from the project as no amount of money is worth dealing with such a mouth-breathing dumbass who has their head wedged up 1997's backside. There's handholding, and then there's putting up with bullshit. That code treads squarely into the latter and that's time to take out the paddle, smack them on the ass, the slap the dunce cap on their head to sit them in the corner while the rest of the class laughs at them. You can only mollycoddle people so far before it treads into "You know what, go flip burgers"
give them ckeditor or something like that to input their html - it does a great job of stripping the tags and attributes you don't want and closing the tags etc even when people edit the source directly.