irwan

Split to long words.

Apr 18th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.42 KB | None | 0 0
  1. <?PHP
  2. // To long
  3. $text = "Hi, this is a set with a too long woooooooooooooooooooooooooooooooooooooooooooooooooooord";
  4. // set maximum lenght
  5. $max = 30;
  6. // only to separate the long words
  7. $newtext = "";
  8. $words = explode ( " ", $text);
  9. foreach($words as $word)
  10. {
  11.  if(strlen($word)>$max)
  12.  {
  13.  $newtext.=chunk_split ( $word, $max, "-<br />");
  14.  }
  15.  else
  16.  {
  17.  $newtext.=$word." ";
  18.  }
  19. }
  20. // the output
  21. echo $newtext;
  22. ?>
Advertisement
Add Comment
Please, Sign In to add comment