Image

Imagemuerte wrote in Imagephp

PHP Close Open Tags?

I have some text, well more appropriately some HTML. Say it's:

$i = "Hello there <b>Mr. Anderson</b>.<br />
<i>How are you today?</i><br />
Here is a list of things to do:
<br />
<br />
<ul>
  <li>Mown Lawn</li>
  <li>Clean Gutters</li>
  <li>Kill Morpheus</li>
</ul>";


If I want to split that entry in half...

$a = substr($i,0,strlen($i) / 2);

I can't print out $a, because it will have some HTML tags that are left open. What's the easiest way in PHP to take a given chuck of text and close all the left open HTML tags in it? Someone must have done this.