Remove excessive line returns

后端 未结 5 1535
野的像风
野的像风 2021-01-13 09:12

I am looking for something like trim() but for within the bounds of a string. Users sometimes put 2, 3, 4, or more line returns after they type, I need to sanitize this inp

5条回答
  •  伪装坚强ぢ
    2021-01-13 09:42

    To consider all three line break sequences:

    preg_replace('/(?:\r\n|[\r\n]){2,}/', "\n\n", $str)
    

提交回复
热议问题