maghiel
04-04-2007, 02:02 PM
Oi,
I'm writing a script that imports lines from a plain text file to a database.
Now all values are seperated by a newline, but not given by \n but given by ASCII values CR and LF(13 and 10).
So I wrote this script:
<?php
$file = 'file.txt';
echo ('<pre>');
echo ('<b>Import script</b><br/>');
$handle = fopen($file, 'r');
$n = 0;
while(!feof($handle))
{
$n++;
$line = stream_get_line($handle, 4096, chr(13) . chr(10));
echo ('Line ' . $n . ': ' . $line . '<br/>');
}
echo ('</pre>');
?>
But that gives everything back as just one
Line 1: Bla
Bla
Bla
Bla
What am I doing wrong?
I'm writing a script that imports lines from a plain text file to a database.
Now all values are seperated by a newline, but not given by \n but given by ASCII values CR and LF(13 and 10).
So I wrote this script:
<?php
$file = 'file.txt';
echo ('<pre>');
echo ('<b>Import script</b><br/>');
$handle = fopen($file, 'r');
$n = 0;
while(!feof($handle))
{
$n++;
$line = stream_get_line($handle, 4096, chr(13) . chr(10));
echo ('Line ' . $n . ': ' . $line . '<br/>');
}
echo ('</pre>');
?>
But that gives everything back as just one
Line 1: Bla
Bla
Bla
Bla
What am I doing wrong?