How to replace one or two consecutive line breaks in a string?

后端 未结 3 1244
暖寄归人
暖寄归人 2020-12-01 23:55

I\'m developing a single serving site in PHP that simply displays messages that are posted by visitors (ideally surrounding the topic of the website). Anyone can post up to

3条回答
  •  情歌与酒
    2020-12-02 00:24

    Something like

    preg_replace('/(\r|\n|\r\n){2,}/', '

    ', $text);

    should work, I think. Though I don't remember PHP syntax exactly, it might need some more escaping :-/

提交回复
热议问题