Jump to content

Automatically Close Unclosed HTML Tags


jyushinx

Recommended Posts

Hi,

 

I have a situation where I am pulling text previews from a database using the SUBSTR mysql function. The issue with this is that it can cut right through tags, leaving them unclosed. This obviously causes problems with the site display.

 

I need a function which will run through the chunk of HTML and add any necessary closing tags. I've found one or two of these functions floating around the internet, but I keep running into the same issue with them: they do not interpret tags such as <input /> as being closed. So they add a </input> tag even though it is unnecessary. This could cause some serious display problems with the page. For example, if there was a tag <div />, then the parser would add a </div>. Not good. Why would a tag <div /> be used you ask? Well this is user input. Who knows what's going to be done. I expect the worst though.

 

Does anyone have or know of any functions which is more intelligent when finding open ended tags and closing them?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/104470-automatically-close-unclosed-html-tags/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.