note 95230 added to function.substr

From: Date: Sun, 20 Dec 2009 00:29:10 +0000
Subject: note 95230 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-164146@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 69.147.83.197 Probable Submitter: 67.242.44.119 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/95230 Del: integrated -- https://master.php.net/note/delete/95230/integrated Del: useless -- https://master.php.net/note/delete/95230/useless Del: bad code -- https://master.php.net/note/delete/95230/bad+code Del: spam -- https://master.php.net/note/delete/95230/spam Del: non-english -- https://master.php.net/note/delete/95230/non-english Del: in docs -- https://master.php.net/note/delete/95230/in+docs Del: other reasons-- https://master.php.net/note/delete/95230 Reject -- https://master.php.net/note/reject/95230 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164146) next »