Re: string effect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/29/08, Alain Roger <raf.news@xxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux