I can't find the post, but a few days ago somone asked a similar question. Someone else replied with a little function that followed this procedure: break the string by spaces, check how long each word is, then truncate the string if it's too long. It's a fairly simple concept using substr(), a for, and an if-then-else. You may also want to look at split(). (For use in this function.)