Home > Backend Development > PHP Tutorial > 小弟我的从TXT中读取的矩阵,但是每一行最后一个值总跟下一行第一个值一起输出。如何破

小弟我的从TXT中读取的矩阵,但是每一行最后一个值总跟下一行第一个值一起输出。如何破

WBOY
Release: 2016-06-13 12:26:21
Original
1060 people have browsed it

我的从TXT中读取的矩阵,但是每一行最后一个值总跟下一行第一个值一起输出。怎么破?

新手请教各位大神: 我的矩阵每一行最后一个值总跟下一行第一个值一起输出。怎么破?jsl_mini.txt里是一个矩阵:
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].'
';
?>
输出结果为:
jsl_mini.txt
2015/5/4
4857.00 
4780.00 
4480.46 2015/5/5
4692.00 
4736.00

就是红色这一行,分开4480.46 和2015/5/5用什么?

------解决思路----------------------
建议这样写

$file = 'jsl_mini.txt';<br />$rows = file($file, FILE_SKIP_EMPTY_LINES <br><font color='#FF8000'>------解决思路----------------------</font><br> FILE_IGNORE_NEW_LINES);<br />foreach($rows as $content) {<br />  $array = explode("\t", $content);<br />  echo $array[0].'<br/>';<br />  echo $array[1].'<br/>';<br />  echo $array[2].'<br/>';<br />  echo $array[3].'<br/>';<br />}<br />
Copy after login

FILE_SKIP_EMPTY_LINES 跳过空行
FILE_IGNORE_NEW_LINES 去掉换行符
------解决思路----------------------
<br /><?php<br />$data = <<<TXT<br />2015/5/4	4857.00	4780.00	4480.46<br />2015/5/5	4692.00	4736.00	4298.71<br />TXT;<br /><br />$d = explode("\r\n", $data);<br />foreach($d as $k){<br />    $t = explode("\t", $k);<br />    foreach($t as $t1){<br />        echo $t1.'<br>';<br />    }<br />}<br />?><br />
Copy after login


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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template