title: PHP substr but keep HTML tags?
body: <p>I am wondering if there is an elegant way to trim some text but while being HTML tag aware?</p>
  
  <p>For example, I have this string:</p>
  
  <pre><code>$data = '&lt;strong&gt;some title text here that could get very long&lt;/strong&gt;';
  </code></pre>
  
  <p>And let's say I need to return/output this string on a page but would like it to be no more than X characters.  Let's say 35 for this example.</p>
  
  <p>Then I use:</p>
  
  <pre><code>$output = substr($data,0,20);
  </code></pre>
  
  <p>But now I end up with: </p>
  
  <pre><code>&lt;strong&gt;some title text here that 
  </code></pre>
  
  <p>which as you can see the closing strong tags are discarded thus breaking the HTML display.</p>
  
  <p>Is there a way around this?  Also note that it is possible to have multiple tags in the string for example:</p>
  
  <pre><code>&lt;p&gt;some text here &lt;strong&gt;and here&lt;/strong&gt;&lt;/p&gt;
  </code></pre>