Script that will get rid of empty lines?

Discussion in 'PHP' started by matty005, Apr 5, 2007.

  1. #1
    Hi, i have a lot of php files that have a line between each line of code. For example, they look like this:

    <?php

    line1

    line2

    ?>

    Its so annoying, and i dont want to waste time getting rid of each line. I coded this myself, so could someone advise a program that i could use to get rid of these lines?

    Thank you
     
    matty005, Apr 5, 2007 IP
  2. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    jitesh, Apr 5, 2007 IP
    nico_swd likes this.
  3. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #3
    srobona, Apr 5, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can I make a guess and say that you originally wrote that code in Windows and are now looking at it in UNIX / Linux? If I were to guess, I'd say it's an end-of-line character issue.

    The only problem with removing empty lines willy-nilly is that you will lose any empty lines you put there on purpose.

    Assuming my assumption about EOL is correct, I'd just grab an editor that works properly with either EOL and be done with it.
     
    TwistMyArm, Apr 5, 2007 IP
  5. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    manilodisan, Apr 5, 2007 IP
  6. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #6
    This happens to me sometimes to..it's so annoying. It has something to do with linux like the above mentioned. I'm guessing something to do with nano/ftp settings of the server >.>
     
    Rub3X, Apr 5, 2007 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It's not to do with the FTP server settings: if anything, it would be related to the FTP client.

    Windows EOL requires two characters: "\r\n". UNIX / Linux requires one: "\n". The "\r" is technically a different character (carriage return as opposed to a new line) but it's interpreted as such.

    Hence, when Windows creates a file with the two characters, UNIX / Linux sees that file and sees basically "\r" (which it displays as a new line) followed directly by the new line character resulting in every second line being blank (and empty).

    In theory an FTP client should be able to determine that a) it's grabbing a text file and hence b) rewrite the EOL character for the appropriate target OS.

    Like I said, though, it's best just to grab an editing environment that understands both (well all, actually, as Mac OS, for example, has a different EOL again).
     
    TwistMyArm, Apr 5, 2007 IP
  8. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #8
    Dreamweaver search and replace option.

    Peace,
     
    Barti1987, Apr 5, 2007 IP
  9. Dima_2005

    Dima_2005 Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hmm, if you're a good coder you can create a good code that will do that for you....

    There is a function like trim...

    So then do first the trim of the script, then the echo of the trimmed script
     
    Dima_2005, Apr 6, 2007 IP
  10. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #10
    OK, I don't want to start a flamewar here, but I don't see the point in writing code to do this as if you move your code back and forth between different operating systems you would have to do this every time you want to use your code in a different OS.

    With a smart editor you don't even have to worry about silly little things like that. If you dual boot between Windows and Linux (for example) you could have the scripts on a 'shared' drive so that you don't even have to copy the code... no matter which OS you're in, you're using the same code.

    Maybe I'm missing something, but I really don't see the point to trying to work around this problem through code beautifiers (which won't necessarily work correctly) or your own code when the problem is solved with half decent editors... what am I missing here?
     
    TwistMyArm, Apr 6, 2007 IP
  11. crazydeeznuts

    crazydeeznuts Banned

    Messages:
    4
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Have you tried Crimson Editor? That fixed the same problem I had and its free... :cool:
     
    crazydeeznuts, Apr 6, 2007 IP