I have a code where I make a query with php and sql server, the query brings me some records, then I create a text file (.TXT) and with a cycle while(true)
I write the records and when there are no records that write I give the order break
to stop the cycle.
The issue is that in order to differentiate a record from another I write a "\r\n"
to jump to the next line and write the record that follows.
The records write them well in the file (.TXT) just as I need it
What is the problem?
When you write the last record you leave a blank line at the end.
Obviously the blank space is because of placing '' "\ r \ n" 'but if I do not place it I will write all the records in a straight line, without skipping line
There will be a way to erase that space left at the end of the file or there is some way to make the line break between records without leaving that space.
This is the code of when I make the line break:
$notas = "";
$notas_completo = str_pad($notas, 255, " ", STR_PAD_RIGHT);
fwrite($ruta, $notas_completo."\r\n");
Basically in the variable $notas
I load the data that I will write and in fwrite
to insert, so I insert all the data, and if they are set in the fwrite
I place the "\r\n"
since $notas
is the last data, you can ignore the str_pad
I only use it to fill in space in case the registry lacks characters.
This is the blank space that leaves me in the file (.TXT)
Update:
I know that in this file (.TXT)
is something like a space that indicates the end of the file, my query only has 100 records already counted, and as they are fixed in the screenshot that I attached, does not say 100 lines, says 101
If I delete line 101 and save, I have left as it should be, with 100 lines