Posted By

gdonald on 09/27/06


Tagged

breakup long lines


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
jamesming


php breakup long lines


 / Published in: PHP
 

  1. function breakUpLongLines( $text, $maxLength=80 )
  2. {
  3. $counter = 0;
  4. $newText = '';
  5. $array = array();
  6.  
  7. $textLength = strlen( $text );
  8.  
  9. for( $i = 0; $i <= $textLength; $i++ )
  10. {
  11. $array[] = substr( $text, $i, 1 );
  12. }
  13.  
  14. $textLength = count( $array );
  15.  
  16. for( $x = 0; $x < $textLength; $x++ )
  17. {
  18. if( preg_match( "/[[:space:]]/", $array[ $x ] ) )
  19. {
  20. $counter = 0;
  21. }
  22. else
  23. {
  24. $counter++;
  25. }
  26.  
  27. $newText .= $array[ $x ];
  28.  
  29. if( $counter >= $maxLength )
  30. {
  31. $newText .= ' ';
  32.  
  33. $counter = 0;
  34. }
  35. }
  36.  
  37. return $newText;
  38. }

Report this snippet  

You need to login to post a comment.