Re: Remove blank lines from a file
| From: | Nathan Rixham | Date: | Mon, 24 May 2010 02:20:03 +0000 |
| Subject: | Re: Remove blank lines from a file | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-305473@lists.php.net to get a copy of this message | ||
Robert Cummings wrote:
Nathan Rixham wrote:lol ahh hell yeah; trim() it ;) I'm done for the night best, nathanYes it was client stripping out extra whitespace! thanks Rob, replicated your results: 1 2 3 4 5 6 and then 'fixed' to give what's needed: preg_replace( "/(((\r|)\n)(\h*|))+/im", '\\1' , $input ); the above keeps line termination the same as in the source file; can you give it a quick check your side to ensure it works (if you don't mind)?No, no, you missed my meaning... I don't care about line ending... I care about trailing whitespace on non-empty lines.modified one that 'cleans' the new lines: preg_replace( "/((\r|)\n(\h*|))+/im", PHP_EOL , $input );Yes, this is preferred with respect to line ending IMHO. But it still strips trailing whitesapce. Almost there... but you've also got that first blank line still hanging around which is supposed to be removed :D