![]() |
Att.: scriptfreaks - Removing empty lines from textfile w/php
Hi,
We have a script that is adding new lines for no apparent reason at this time. I want to get rid of the empty lines and re-order the text file every time somebody ads her/his name. The file is pretty simple, just lines, like this: line1 ... ... line2 ... line1001 ... I want to loose the ... lines and have it all nicely formatted, like this line1 line2 line1001 I use this script to add lines: PHP Code:
Thanks, Paul |
Thanks :p
|
Try putting the \n at the end rather than at the start.
fwrite($FilePointer, "$newitem\n"); or fputs($FilePointer, "$newitem\n"); |
just a guess, after you run your insert, rebuild the file?
$file = file_get_contents($FileName); $file = preg_replace("\n\n",$file); fwrite($FilePointer,$file); --- eh, nix that. probably an ugly way to do it. just get the file fixed and insert correct new lines like rowan said. |
put this as line #4
$newitem = trim($newitem); im new at this so i could be wrong |
I did notice it just doubles the amoiunt of rows each time I update, add or edit a line from the file. I'm sure it has to do with /n, but I am still fucking around with it.
I'll try some of your options as well. |
None of the above worked, any other takers?
|
get rid of the \n when your appending to the file it already goes to the end of the file. The only time you need \n is if your appending multiple lines
|
Quote:
If I do that, this line2 line3 ... becomes: line2line3 ... Using this code: PHP Code:
|
This works:
PHP Code:
|
| All times are GMT -7. The time now is 01:07 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123