I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage. The original block of text can be a lengthy artic
This is a small fix for mattmac's answer:
preg_replace('/\s+?(\S+)?$/', '', substr($string . ' ', 0, 201));
The only difference is to add a space at the end of $string. This ensures the last word isn't cut off as per ReX357's comment.
I don't have enough rep points to add this as a comment.