Oh, cutString is not all that hard to understand...

- If the string is empty, it returns a "..." to make sure it's clickable if there's a link around. (This causes a few issues with album descriptions becoming "...", I need to fix that.)
- If we don't want to test for multibyte strings, we simply cut the string and make sure to remove any half-cut entities at the end of the string. It's the easier version, it doesn't test for long words.
- If we need the string to be parsed in the end, we do it now, so that HTML tags can be correctly stripped later...
- Now we mark all entities and HTML tags as a single special character, into a work string. (Note for myself: tags should simply be stripped, rather than reduced to a single character. That makes 2 wasted bytes for self-closing tags...)
- If that string is short enough, we return the original, parsed string, as it's shorter than what's required on screen, even though the raw string is longer.
- Then we store all of the entities, HTML tags and special characters into an array.
- Then we cut the work string. (Hmm, maybe I
should use mb_substr on this..........)
- Time for long word check: for all words that are longer than the desired maximum word length, we add a ­ entity inside them to break them into two words in case it doesn't fit in the final HTML rendition. ­ is very useful, because it only shows up when needed.
- Now we're done with the string cutting, we simply restore the entities and HTML tags...
- And if there's a hard limit on the string size (for instance, if you want to store it in a 255-byte VARCHAR in the database), we cut the string again and strip all half-cut entities from the end.
- And voilà !
Obviously there are a few issues which I mentioned above, and never considered before... No biggie, but still...