Code solutions to PHP, JS, CSSCode source PHP, JS, CSS

Spread your code soluces to the world

Love me
Solucior » PHP » wordwrap without breaking words

wordwrap without breaking words

05/18/2011 by Dux   -   not rated

A simple function to cut a character string without breaking words.

string wrap_word ( string $str [, int $length = 350] )

source code



 
function wrap_word($str, $length=350) {
       
$str = strip_tags($str);
       if (
strlen($str) > $length) {
           for (
$i = $length; $i > 0; $i--) if (preg_match("/\s/", $str{$i})) break;
           
$str = substr($str, 0, $i)."...";
       }
       return
$str;
}
Rate this code     |     Copied : 15x

Comments for wordwrap without breaking words

No comment
Add a comment Nickname
ZOOM


wordwrap without breaking words
Automatic search result page
Horizontal scroll div with javascript
Scroll div with javascript
Make dir and upload files via FTP