1

Possible Duplicate:
How to Truncate a string in PHP to the word closest to a certain number of characters?

I have a string of keywords like below

word1, word3, word3, word4, word5

Now say this list is 400 chars long. I only want the keywords upto the 255 character but I also want to trim the last word as it may only be half a word.

Say I trim the keyword list and end up with this

word1, word3, word3, wo

How do I make sure I trim the last word only if it's half a word

Any ideas on this? I don't know where to start

By the way I'm using PHP

Community
  • 1
  • 1
Sean H Jenkins
  • 1,770
  • 3
  • 21
  • 29

1 Answers1

2
$str = wordwrap($str, 28);
$str = explode("\n", $str);
$str = $str[0]