Clean and keep line breaks

Hello,

I want to keep line spaces in comments but clean more then 2 after each.

Example:

$sentence="This is my first sentence
This will be in a new row
This will be too in a new row but not separated with 3line breaks just with

one

";
And i want to output just this:

$sentence="This is my first sentence
This will be in a new row

This will be too in a new row but not separated with 3line breaks just with
one
";
Please Help

Thanks in Advance

First there seems to be an issue with your examples.

You have the following as your input

$sentence="This is my first sentence
This will be in a new row
This will be too in a new row but not separated with 3line breaks just with

one

";

And then this as your wanted output

$sentence="This is my first sentence
This will be in a new row

This will be too in a new row but not separated with 3line breaks just with
one
";

What are the business rules for establishing an extra line break after “This will be in a new row” (since it wasn’t part of the input)?

If you are trying to reformat the user’s entire comment, I’m going to suggest stopping right there! You are playing with grammar and the user may have written it correctly and after you reformat it, the comment might not make any sense anymore or worse, it may take on an entirely different meaning.

If you are trying to remove any extra line breaks at the end of the comment, that is an easy task (using [fphp]rtrim[/fphp]).