On 2/29/08, Alain Roger <[EMAIL PROTECTED]> 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/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php