title: Fixing unclosed HTML tags
body: <p>I am working on some blog layout and I need to create an abstract of each post (say 15 of the lastest) to show on the homepage. Now the content I use is already formatted in html tags by the textile library. Now if I use substr to get 1st 500 chars of the post, the main problem that I face is how to close the unclosed tags.</p>
  
  <p>e.g</p>
  
  <pre><code>&lt;div&gt;.......................&lt;/div&gt;
  &lt;div&gt;...........
       &lt;p&gt;............&lt;/p&gt;
       &lt;p&gt;...........| 500 chars
       &lt;/p&gt;
  &lt;div&gt;  
  </code></pre>
  
  <p>What I get is two unclosed tags &lt;p> and &lt;div> , p wont create much trouble , but div just messes with the whole page layout. So any suggestion how to track the opening tags and close them manually or something?</p>