acer0169 Posted July 31, 2009 Share Posted July 31, 2009 I'm sure this is an easy thing to do, but I can't seem to get it working.. I've been using this.. substr($row['title'], 0, 55) ..to cut my strings down to 55 characters, but this often cuts a word in half. I would like to know how I can cut off a string after the last whole word which fits within a 55 character limit. Thanks in advance, Ace. (first post also, hi everyone!!) Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 31, 2009 Share Posted July 31, 2009 Unless there's already a function for this, probably the easiest way would be to use the wordwrap function to get lines of the desired lenth, then explode the string and use the first index of the resulting array. Alternatively, you could explode the string by the space, and loop through the array checking the length of each part. If adding the word doesn't take you over the limit, append it to the generated string. If it does, don't add it and break out the loop. Quote Link to comment Share on other sites More sharing options...
acer0169 Posted July 31, 2009 Author Share Posted July 31, 2009 Thanks GingerRobot! I think the wordwrap and explode method would be easiest for me. I knew there was some way to do this. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.