replace blank lines in php

前端 未结 6 1320
执笔经年
执笔经年 2020-12-20 03:26

How do I remove multiple blank lines from a string. I have looked at the examples on stackoverflow and have tried to change my code accordingly but I am not getting the rig

6条回答
  •  庸人自扰
    2020-12-20 04:13

    Try this one:

    $str =preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\r\n", $str);
    

    The output file will give same output on simple notepad and also on text editors eg Notepad++.

提交回复
热议问题