title: Smarter word-wrap in PHP for long words?
body: <p>I'm looking for a way to make word-wrap in PHP a bit smarter. So it doesn't pre-break long words leaving any prior small words alone on one line.</p>
  
  <p>Let's say I have this (the real text is always completely dynamic, this is just to show):</p>
  
  <pre><code>wordwrap('hello! heeeeeeeeeeeeeeereisaverylongword', 25, '&lt;br /&gt;', true);
  </code></pre>
  
  <p>This outputs:</p>
  
  <blockquote>
    <p>hello!<br>
    heeeeeeeeeeeeeeereisavery<br>
    longword</p>
  </blockquote>
  
  <p>See, it leaves the small word alone on the first line.
  How can I get it to ouput something more like this:</p>
  
  <blockquote>
    <p>hello! heeeeeeeeeeee<br>
    eeereisaverylongword</p>
  </blockquote>
  
  <p>So it utilizes any available space on each line. I have tried several custom functions, but none have been effective (or they had some drawbacks).</p>