How would you go about removing extra line breaks for example:
text text text
text text
And i would like it to be this way
text text
text
i am already using nl2br($desc) in order for the line breaks to appear at all now how to i limit them to 1
Before using nl2br() replace all sequences of carriage return or new line characters with a single newline:
$result = preg_replace('/[\r\n]+/', "\n", $desc);
See it working online: ideone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With