PHP multiple new lines

前端 未结 4 1106
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 16:27

I\'m a little stuck. How do I remove multiple newlines which are in a row with one newline. There could be anything up to 20 newlines next to each other. For example

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 17:09

    Try this one:

    $str = "Hello\n\n\n\n\nWorld\n\n\nHow\nAre\n\nYou?";
    $str = preg_replace("/\n+/", "\n", $str);
    print($str);
    

提交回复
热议问题