Salar Salar - 1 year ago 106
PHP Question

detect not closed html tags in a text, and fix it

I have an html text called news which is generated by ckeditor, so it may contain html tags like bold, italic, paragraph and....

I want to choose the first 100 characters of it and show them to the users of my app. but choosing the first 100 characters of news may cause to choose an html text which has unclosed tags(the closing tags of my html text may be after the character number 100).

is there any PHP or js function to parse a text and fix the unclosed html tags or at least remove unclosed html tags?

Answer Source

As far as removing tags altogether, the strip_tags function in PHP should do the trick.

strip_tags($input, '<br><br/>');

The second argument is the allowed tags (the ones that don't get stripped).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download