Text truncating function that secures both HTML tags and full words
Akshaya K Sahu’s answer to this question at Stack Overflow is a great example of text parsing function that can truncate any HTML-encoded string at given length, taking care of all the needed aspects, i.e.:
- full words,
- properly closed HTML tags and
- respected UTF-8 encoding (double-byte characters!)
I have actually nothing to add to it, so I keep a copy of this code only for my own reference. And only because the original answer lacks some comments.
Read More “Text truncating function that secures both HTML tags and full words”