note 95230 deleted from function.substr by danbrown

From: Date: Sun, 20 Dec 2009 03:45:50 +0000
Subject: note 95230 deleted from function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164150@lists.php.net to get a copy of this message
Note Submitter: Steve at H.O.W.D.Y. Media ---- Interesting and useful function biner(gf) (on Nov 19th, 2009). Just a small typo though, the single $ should be the variable $length. I've made this in to a handy function. <?php //substring without words breaking by biner(gf) function substr_word ($str, $length='0') { return ( $length > 0 ? substr(($str=wordwrap($str,$length,'$$')),0,strpos($str,'$$')) : '' ); } echo substr_word("aa bb ccc ddd ee fff gg hhh iii"); // Empty result echo substr_word("aa bb ccc ddd ee fff gg hhh iii",1); // aa echo substr_word("aa bb ccc ddd ee fff gg hhh iii",3); // aa echo substr_word("aa bb ccc ddd ee fff gg hhh iii",5); // aa bb ?>

« previous php.notes (#164150) next »