Close unclosed HTML tags in PHP

Recently I stumped upon a handy WordPress function which closes HTML tags.

The function name is force_balance_tags().

Taking as an example unclosed list items:

echo force_balance_tags( '<ul>
  <li>this
  <li>is
  <li>a
  <li>list
</ul>' );

It will produce something like this:

<ul>
  <li>this
  </li><li>is
  </li><li>a
  </li><li>list
</li></ul>

6 Comments

Leave a Reply to Kuba Mikita Cancel reply

Your email address will not be published.