My matrix read from TXT, but the last value of each row is always output with the first value in the next row. How did it break?

Source: Internet
Author: User
Novice Ask the big God: my matrix The last value of each row is always output with the first value in the next row. How did it break? Jsl_mini.txt is 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]. '
';
?>
The output is:
Jsl_mini.txt
2015/5/4
4857.00
4780.00
4480.46 2015/5/5
4692.00
4736.00

That's the red line, what's the difference between 4480.46 and 2015/5/5?


Reply to discussion (solution)

It is recommended to write

$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 Skip Blank Line
File_ignore_new_lines Remove line break

 
  ';    }}? >


2015/5/4
4857.00
4780.00
4480.46
2015/5/5
4692.00
4736.00
4298.71

It is recommended to write

$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 Skip Blank Line
File_ignore_new_lines Remove line break


Thank you!

 
  ';    }}? >


2015/5/4
4857.00
4780.00
4480.46
2015/5/5
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.