How to remove unnecessary spaces from a string, so there are no extra spaces in HTML?
I get a row from the DB, and now I'm trying to do something like:
nl2br(trim(preg_replace('/(\r?\n){3,}/', '$1$1', $comment->text)));
But it continues to display as follows:

I need it to work perfectly:

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

source
share