Jump to content

need to read line by line using file_get_contents


michael.davis

Recommended Posts

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;
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.