I’m looking for a PHP function to close HTML tags.
I’m building a site that has admins entering content in a “WYSIWYG” editor. Some of the screens will only show part of the content and then prompt the user to “click for more”. So I need to be able to close all the HTML tags that were opened in the part of the content that is initially displayed.
Thanks for any help
I think you can do this by running the HTML through something like tidy. An extension for this is available in PHP.
For example, suppose you had a fragment like this
Thorny! Dangling tags and a truncation in mid-tag!
Here’s what you’d get back
Pretty impressive! Now all you need to do is just extract the repaired fragment back out of the body element.
See also the answers to PHP: Truncate HTML, ignoring tags