Re: limit on displaying a LONGTEXT filed from MySQL database

From: Date: Mon, 23 Jun 2003 04:38:48 +0000
Subject: Re: limit on displaying a LONGTEXT filed from MySQL database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-152472@lists.php.net to get a copy of this message
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 (artoo_s@hotmail.com) 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 > >

« previous php.general (#152472) next »