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
https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/
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

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);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.