Outputting words instead of characters

I have an area of my website that is meant to produce a small list of recent comments. The problem I am coming up against is that the recent comments trail off at the last characters (and not the words).

It would be my understanding that the majority of this is fixed somewhere in this foreach block that outputs the actual comments in list-item elements:

foreach ($comments as $comment){

$output .= "<li>".strip_tags($comment->comment_author).": " . "<a href=\\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\\" title=\\"on " . $comment->post_title . "\\">" . strip_tags($comment->com_excerpt)

My question is this: assuming this would be done with some sort of regex approach, should I do this each time a single $comments array element is formatted and output or should I somehow apply this tweak to the entire array prior to being processed in the foreach?

You don’t need and shouldn’t use regex for this. Simple string functions will do fine. Use “string reverse position” to locate the last “space” which will be before the last word fragment, and truncate the substring to that length.