dreamwest Posted August 30, 2009 Share Posted August 30, 2009 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?? Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/ Share on other sites More sharing options...
.josh Posted August 30, 2009 Share Posted August 30, 2009 you said it's appearing because of the "r\n". What do you think you need to do to make it go away? Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/#findComment-909169 Share on other sites More sharing options...
dreamwest Posted August 30, 2009 Author Share Posted August 30, 2009 !somehow! work out when the last line will be I need the written file to be line by line so i cant remove it completley Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/#findComment-909178 Share on other sites More sharing options...
trq Posted August 30, 2009 Share Posted August 30, 2009 Once your done you could use rtrim to remove the last newline before writing to the file. Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/#findComment-909183 Share on other sites More sharing options...
dreamwest Posted August 30, 2009 Author Share Posted August 30, 2009 Once your done you could use rtrim to remove the last newline before writing to the file. Just what i was looking for. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/#findComment-909186 Share on other sites More sharing options...
RussellReal Posted August 30, 2009 Share Posted August 30, 2009 you'd have to put it ALL into $buffer before you put it into the file.. to have rtrim() work correctly in this scenario Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/#findComment-909364 Share on other sites More sharing options...
trq Posted August 30, 2009 Share Posted August 30, 2009 That is exactly what he is doing. Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/#findComment-909371 Share on other sites More sharing options...
RussellReal Posted August 30, 2009 Share Posted August 30, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/#findComment-909374 Share on other sites More sharing options...
dreamwest Posted August 31, 2009 Author Share Posted August 31, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/172449-blank-line-at-the-end-of-the-file/#findComment-909554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.