Here one way you can do it (untested): <? function chopper($str,$chars) { while($str{$chars} != ' ' && $chars <= strlen($str)) { $chars++; } $newStr = substr($str,0,$chars); return $newStr; }
$originalText = "The quick brown fox jumped over the lazy dog"; echo chopper($originalText,20); ?> Justin on 23/06/03 10:41 AM, Artoo ([EMAIL PROTECTED]) wrote: > Hi, > > How can I start searching for the first space in a string while starting at > say the 150th character? I'm trying to display the first 150 characters of > an article that is stored in a LONGTEXT filed of a MYSQL database, and > should the 150th character be inside a word, I would want to finish > displaying that word. > > For example supose the 150th character is the v in the word "privileges" I > would want to finish displaying the word and end with "privileges" rather > then ending with"priv" > > thanks > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php