Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Location
    U.S.A
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Remove empty lines

    I have a .txt file that has something like this
    Code:
    1
    			<a href="/projects/emule/">eMule</a>
    			391,631,805
    		
    		
    			2
    			<a href="/projects/azureus/">Azureus</a>
    			162,516,119
    		
    		
    			3
    			<a href="/projects/aresgalaxy/">Ares Galaxy</a>
    			144,396,278
    		
    		
    			4
    			<a href="/projects/bittorrent/">BitTorrent</a>
    			51,850,559
    I need all the empty line deleted.
    I've tried the following
    Code:
    function removeEmptyLines($string)
    {
    return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);
    }
    _____________________________________
    $content = eregi_replace("\"","'",$content);
    $content = eregi_replace("\n","",$content);
    $content = eregi_replace("\r","",$content);
    Thank you for your time and effort,

    Joe

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    So what kind of output are you expecting?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Mar 2008
    Location
    Lakeland, FL
    Posts
    39
    Thanks
    1
    Thanked 3 Times in 3 Posts
    You could load the file with file() and loop through the lines like so:
    PHP Code:
    $newstring '';
    foreach(
    file("some.txt") as $line)
    {
        if(
    trim($line) != '')
        {
            
    $newstring .= $line;        
        }

    I'm not very good with regexp so this would be the way i would do it. May not be the l33t way or the most efficient way but it works


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •