Jump to content

blank line at the end of the file??


dreamwest

Recommended Posts

Im writing to a file but this put a blank line at the end, the reason why is because of r\n which is like<br> in html.

 

 
$current .= $buffer."r\n";  //has over 1000 lines 
file_put_contents($save_as, $current);

 

How can i get rid of this blank line at the end of the file??

 

Link to comment
Share on other sites

That is exactly what he is doing.

 

not from what is shown... there is most likely some sort of a loop surrounding it all.. because than there is absolutely no reason to add the crlf at the end anyway.. in your case he doesn't even need to USE rtrim() he would just remove ."\r\n" lol

Link to comment
Share on other sites

Yeah it is a buffer with a loop, heres the finished script:

 

Check to make sure proper amount of deliminators "|" in a file

$handle = @fopen("1.txt", "r");

if ($handle) {

$count = 1;
    
while (!feof($handle)) {
    
$buffer = trim(fgets($handle, 10096));
$check = explode('|', $buffer);
$check = trim($check[1]);
        
if ($check == "" || $check == " " ){
//delete line
    $err .= "ERROR on line {$count} - {$buffer}<br>";
    }else{
    
      //write the rest to a new file
    $current .= $buffer."\n";
    }
++$count;
}
fclose($handle);
}

$current = rtrim($current);
file_put_contents("2.txt", $current);

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.