How to remove unnecessary whitespaces from string, so there are no extra spaces in HTML??
Im getting string from DB and for now I'm trying to do something like:
nl2br(trim(preg_replace('/(\r?\n){3,}/', '$1$1', $comment->text)));
But it keep displaying like that:

What I need is to get perfect:

How it is done?? Because I'm bad at regex :(
EDIT: $comment->text contains text from DB:
