note 60089 deleted from function.substr by nlopess

From: Date: Mon, 26 Dec 2005 11:10:54 +0000
Subject: note 60089 deleted from function.substr by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100724@lists.php.net to get a copy of this message
Note Submitter: razonklnbd at yahoo dot com ---- i was looking for a function that will work as substr but not on character, i want to subtract word. here is the function that works for me good <?php function my_subline($p_line, $p_start, $p_length=0){ $f_lns=explode(' ', $p_line); $f_end=count($f_lns); if(isset($f_lns[$p_start+$p_length]) && $p_length>0) $f_end=$p_start+$p_length; for($i=$p_start;$i<$f_end;$i++) $f_ln.=$f_lns[$i].' '; return trim($f_ln); } /* * USAGE: * $str="i am Bangladeshi. work for www.suchona.com"; * echo(my_subline($str, 3, 3)); * // Output: * // work for www.suchona.com */ ?> hope it will save some one's valuable time.. :)

« previous php.notes (#100724) next »