View Single Post
Old 2009-02-14, 06:21 AM   #1
Simon
That which does not kill us, will try, try again.
 
Simon's Avatar
 
Join Date: Aug 2003
Location: Conch Republic
Posts: 5,150
Send a message via ICQ to Simon Send a message via AIM to Simon Send a message via Yahoo to Simon
Quote:
Sort of related - I have a bunch of stories which I want to use - but all the lines are double spaced
Is there a way of clearing all empty lines using php...
As an alternative, using regex in a text editor you can do this...

Search for: \r\r
Replace with: \r

Finds two carriage returns in a row and replaces them with one carriage return.

If I'm searching for *nix line feeds instead of carriage returns, I use \n instead of \r in the search and replace.

Again, I'm not sure which Windows editors do these kinds of searches, but BBEdit on the Mac lets you run these kinds of searches on a whole folder full of text files and process them as a batch right from the text editor.

If you don't need to preserve the order of the lines, one other option would be to sort the text file, which would put all the blank lines together so you can delete them. Then cleaned text file could be opened in Excel or other spreadsheet program where the lines can be sorted randomly again if you need to do that before importing to somewhere.
__________________
"If you're happy and you know it, think again." -- Guru Pitka

Last edited by Simon; 2009-02-14 at 06:28 AM..
Simon is offline   Reply With Quote