note 100688 deleted from function.wordwrap by danbrown

From: Date: Sun, 31 Oct 2010 21:38:29 +0000
Subject: note 100688 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173620@lists.php.net to get a copy of this message
Note Submitter: patigunjan at gmail dot com ---- A small change to venimus's cutstr function below. If the upper bound is strict, adding $ellipsis may cause the final string to be sometimes larger than the expected bound Also added better defaults and changed to a more intuitive name (IMHO) <?php function stringWrap($str, $length, $ellipsis='...') { $cut = (array) explode('\n\n', wordwrap($str , $length - strlen($ellipsis), '\n\n')); return $cut[0].(strlen($cut[0]) < strlen($str) ? $ellipsis : ''); } ?>

« previous php.notes (#173620) next »