[SOLVED] fwrite and newline chars
Posted: Tue Apr 12, 2005 8:00 am
I have been trying to write a little bit of simple code to output a 2 line file with some exchange rates in it.
Problem is that even though I have put \n for new line characters, when I read the file back it always comes back as one line.
I have tried using fgets and fgetss to read it back and even though the PHP manual says length is not required for fgets it gives and a warning and then displays both writes as one line.
and then to read the file
the \n charaters are embedded in the output but they don't cause the the fgets to read one line at a time. What is wrong?
looking at the created file shows both rows on one line like this:
USD=1.2985\nEUR=0.68540\n
Why?
tia
Problem is that even though I have put \n for new line characters, when I read the file back it always comes back as one line.
I have tried using fgets and fgetss to read it back and even though the PHP manual says length is not required for fgets it gives and a warning and then displays both writes as one line.
Code: Select all
$filename = "e;currencies.txt"e;;
$fp2 = fopen( $filename, "e;w"e; );
$rec = 'USD='.$usd.'\n';
fwrite( $fp2, $rec, strlen($rec));
$rec = 'EUR='.$eur.'\n';
fwrite( $fp2, $rec, strlen($rec));
fclose( $fp2 );Code: Select all
$filename = "e;currencies.txt"e;;
$fp3 = fopen( $filename, "e;r"e; );
$rec = fgets($fp3);
echo '<br />currencies<br />';
echo $rec;
fclose( $fp3 );looking at the created file shows both rows on one line like this:
USD=1.2985\nEUR=0.68540\n
Why?
tia