Jump to content

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.