Re: string effect

From: Date: Fri, 29 Feb 2008 21:28:53 +0000
Subject: Re: string effect
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-270777@lists.php.net to get a copy of this message
On 2/29/08, Alain Roger <raf.news@gmail.com> wrote: > Text is cut off based on (numbers of words, number of characters,..) ? > what is the algorithm for such thing ? Mr. Heyes more or less prompted me to go dig for my other, slightly heavier version, that doesn't chop words up: function breakUpLongLines( $text, $maxLength=96 ) { $counter = 0; $newText = ''; $array = array(); $textLength = strlen( $text ); for( $i = 0; $i <= $textLength; $i++ ) { $array[] = substr( $text, $i, 1 ); } $textLength = count( $array ); for( $x = 0; $x < $textLength; $x++ ) { if( preg_match( "/[[:space:]]/", $array[ $x ] ) ) { $counter = 0; } else { $counter++; } $newText .= $array[ $x ]; if( $counter >= $maxLength ) { $newText .= ' '; $counter = 0; } } return $newText; } -- Greg Donald http://destiney.com/

« previous php.general (#270777) next »