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('/[
]+/', "
", $desc);
See it working online: ideone
after nl2br()
do:
$desc = preg_replace('#(<br[ ]?[\/]?>[
]*)+#','<br/>',$desc);