This little function cuts a string to a specified length while keeping the word boundaries under consideration.

This little function cuts a string to a specified length while keeping the word boundaries under consideration.
 
<code class=”prettyprint”>
function cuttext($text, $chars = 100)
{
    if (strlen($text) > $chars) {
        $newtext = substr($text, 0, $chars);
        return preg_replace ("{\s+\S+$}", "...", $newtext);
    } else {
        return $text;
    }
}
</code>

Bookmark this!

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • Digg
  • Fark
  • Furl
  • MisterWong
  • NewsVine
  • Reddit
  • Spurl
  • StumbleUpon
  • TailRank
  • Technorati

Submit your comment

vision22.net

Copyright © 2007