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
在nl2br()
之后:
$desc = preg_replace('#(<br[ ]?[\/]?>[\r\n]*)+#','<br/>',$desc);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.