How do I truncate this PHP

Out of context: Reply #12

  • Started
  • Last post
  • 16 Responses
  • Mick0

    Rather than just using substring, you could split the text block using the space character so it splits all words and converts them to an array, then trim the array to how many words you want, then joing the array back to a string. This would give you a word limit, but if you need the text to fit somewhere it won't be much good if people enter exceptionally long or short words since there will be a big variation in how much space the string will take up.

View thread