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?

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.