phpnewbie112 Posted July 20, 2008 Share Posted July 20, 2008 Hello, I am trying to read the lines output of a txt file using the foreach() as follow but it only returns the 1st line. <?php $handle = fopen("test1.txt", "r"); $data = fgetcsv($handle, 1000, ","); $arr = array($data); reset($arr); $row = 1; foreach ($arr as $value) { $num = count($data); $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); ?> pls advice Link to comment https://forums.phpfreaks.com/topic/115683-solved-foreach/ Share on other sites More sharing options...
ignace Posted July 20, 2008 Share Posted July 20, 2008 $lines = file("path/to/file"); foreach ($lines as $line) { echo $line . "<br />\n"; } Link to comment https://forums.phpfreaks.com/topic/115683-solved-foreach/#findComment-594739 Share on other sites More sharing options...
phpnewbie112 Posted July 20, 2008 Author Share Posted July 20, 2008 thanks a lot. it is working Link to comment https://forums.phpfreaks.com/topic/115683-solved-foreach/#findComment-594755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.