note 53605 added to function.substr

From: Date: Tue, 07 Jun 2005 10:43:41 +0000
Subject: note 53605 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-90046@lists.php.net to get a copy of this message
I have developed a function with a similar outcome to jay's Checks if the last character is or isnt a space. (does it the normal way if it is) It explodes the string into an array of seperate works, the effect is... it chops off anything after and including the last space. <? function limit_string($string, $charlimit) { if(substr($string,$charlimit-1,1) != ' ') { $string = substr($string,'0',$charlimit); $array = explode(' ',$string); array_pop($array); $new_string = implode(' ',$array); return $new_string.'...'; } else { return substr($string,'0',$charlimit-1).'...'; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53605 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53605&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53605&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53605&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53605&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53605&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53605&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90046) next »