Replace multiple newlines, tabs, and spaces

前端 未结 10 1868
情深已故
情深已故 2020-11-27 05:56

I want to replace multiple newline characters with one newline character, and multiple spaces with a single space.

I tried preg_replace(\"/\\n\\n+/\", \"\\n\",

10条回答
  •  粉色の甜心
    2020-11-27 06:58

    I would suggest something like this:

    preg_replace("/(\R){2,}/", "$1", $str);
    

    This will take care of all the Unicode newline characters.

提交回复
热议问题