I read the matrix from TXT, but the last value of each row is always output together with the first value of the next row. How can this problem be solved? For beginners, please kindly advise: the last value of each line in my matrix is always output together with the first value in the next line. How can this problem be solved? Jsl_mini.txt contains a matrix:
2015/5/4 4857.00 4780.00 4480.46
2015/5/5 4692.00 4736.00 4298.71
$ File = 'jsl_mini.txt ';
Echo $ file .'
';
$ Content = file_get_contents ($ file );
$ Array = explode ("\ t", $ content );
Echo $ array [0].'
';
Echo $ array [1].'
';
Echo $ array [2].'
';
Echo $ array [3].'
';
Echo $ array [4].'
';
Echo $ array [5].'
';
?>
Output result:
Jsl_mini.txt
4857.00
4780.00
4480.46
4692.00
4736.00
It is the red line. what is the purpose of separating 4480.46 and?
Reply to discussion (solution)
We recommend that you write this code.
$file = 'jsl_mini.txt';$rows = file($file, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);foreach($rows as $content) { $array = explode("\t", $content); echo $array[0].'
'; echo $array[1].'
'; echo $array[2].'
'; echo $array[3].'
';}
FILE_SKIP_EMPTY_LINES skips empty lines
FILE_IGNORE_NEW_LINES remove line breaks
'; }}?>
4857.00
4780.00
4480.46
4692.00
4736.00
4298.71
We recommend that you write this code.
$file = 'jsl_mini.txt';$rows = file($file, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);foreach($rows as $content) { $array = explode("\t", $content); echo $array[0].'
'; echo $array[1].'
'; echo $array[2].'
'; echo $array[3].'
';}
FILE_SKIP_EMPTY_LINES skips empty lines
FILE_IGNORE_NEW_LINES remove line breaks
Thank you!
'; }}?>
4857.00
4780.00
4480.46
4692.00
4736.00
4298.71
Thank you!