Return to Snippet

Revision: 1257
at September 27, 2006 08:53 by gdonald


Updated Code
function breakUpLongLines( $text, $maxLength=80 )
{
  $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;
}

Revision: 1256
at September 27, 2006 08:51 by gdonald


Initial Code
function breakUpLongLines( $text, $maxLength = '' )
{
if( !$maxLength )
{
$maxLength = $GLOBALS[ 'SITE_MAX_LONG_LINE' ];
}

$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;
}

Initial URL


Initial Description


Initial Title
php breakup long lines

Initial Tags


Initial Language
PHP