Re: Get just first 200 characters of field?

From: Date: Wed, 18 Oct 2000 15:22:08 +0000
Subject: Re: Get just first 200 characters of field?
References: 1  Groups: php.db php.general 
Request: Send a blank email to php-general+get-20908@lists.php.net to get a copy of this message
if you're not concerned with ending at a sentance, use substr(). I usually do substr()."..." - hope this helps, Joe Tim Parkin wrote: > <?php > function makebrief($string,$temp_max_length) { > $temp_max_length = $max_length; > $string_length=strlen($string); > > // Keep reducing the string until we reach a . or ! or ? hence only > leaving a full sentence at the end > do { > if((!strcmp(substr($string,$temp_max_length,1),".")) || > (!strcmp(substr($string,$temp_max_length,1),"?")) || > (!strcmp(substr($string,$temp_max_length,1),"!"))) break; > $temp_max_length--; > } while($temp_max_length<$string_length); > > // if this results in a string smaller than zero then perform the same > operation down to the nearest space. > if ($temp_max_length < 1 ) { > $temp_max_length = $max_length; > do { > if(!strcmp(substr($string,$temp_max_length,1)," ")) break; > $temp_max_length--; > } while($temp_max_length<$string_length); > } > > // trim the string > return > trim(substr($string,0,$temp_max_length))."&nbsp;.&nbsp;.&nbsp;."; > } > ?> > > -----Original Message----- > From: James Montz [mailto:jmontz@ncn.net] > Sent: Wednesday, October 18, 2000 15:01 > To: php-db@lists.php.net; php-general@lists.php.net > Subject: [PHP] Get just first 200 characters of field? > > Im working on my own news managment system for my web site, and I would like > to be able to post on the main page the article header, and just the first > 200 or so characters of the actual content of the article. > > How can this be done? Using PHP3 and MySQL? Is there a specific PHP or > MySQL function that would accomplish this? > > Thanks in advance, > > ____________________ > James C. Montz > Systems Engineer > Northwest Internet Services > > "A complex system that does not work is invariably found to have evolved > from a simpler system that worked just fine. " > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#20908) next »