michael.davis Posted June 20, 2012 Share Posted June 20, 2012 Hi All! I am trying to read line for line from a file that is on a weather site. I can read the file from the internet, but do not want nor need to write the file on the server to source it. Feel it would be duplication. Can someone take a quick look at my code and see what I am missing? <?php //MTR $lines = file_get_contents('http://www.srh.noaa.gov/rtimages/ohx/current_wx/MTRBNA'); $i=1; foreach($lines as $line ){ $var["line" . $i] = $line; $i++; } extract($var); echo $line1; echo $line2; echo $line3; echo $line4; echo $line5; echo $line6; ?> Link to comment https://forums.phpfreaks.com/topic/264519-need-to-read-line-by-line-using-file_get_contents/ Share on other sites More sharing options...
Barand Posted June 20, 2012 Share Posted June 20, 2012 use file() instead Link to comment https://forums.phpfreaks.com/topic/264519-need-to-read-line-by-line-using-file_get_contents/#findComment-1355608 Share on other sites More sharing options...
Barand Posted June 20, 2012 Share Posted June 20, 2012 PS $lines = file('http://www.srh.noaa.gov/rtimages/ohx/current_wx/MTRBNA'); foreach($lines as $line) { echo "$line<br />"; } Link to comment https://forums.phpfreaks.com/topic/264519-need-to-read-line-by-line-using-file_get_contents/#findComment-1355619 Share on other sites More sharing options...
michael.davis Posted June 20, 2012 Author Share Posted June 20, 2012 Ah.... ok that makes sense. Use the file() command rather than the file_get_contents. I am only wanting to pull certain segments of this file. That is why I was looking to use the variable to work with this. Thanks! Mike Link to comment https://forums.phpfreaks.com/topic/264519-need-to-read-line-by-line-using-file_get_contents/#findComment-1355623 Share on other sites More sharing options...
Barand Posted June 20, 2012 Share Posted June 20, 2012 I am only wanting to pull certain segments of this file. That is why I was looking to use the variable to work with this. just use the array indexes instead of constructing the var names echo $lines[0]; etc Link to comment https://forums.phpfreaks.com/topic/264519-need-to-read-line-by-line-using-file_get_contents/#findComment-1355631 Share on other sites More sharing options...
michael.davis Posted June 20, 2012 Author Share Posted June 20, 2012 Ah... awesome! Thank you for the help! Mike Link to comment https://forums.phpfreaks.com/topic/264519-need-to-read-line-by-line-using-file_get_contents/#findComment-1355636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.