Hi I wanted to get some data from a file on the web that is updated every 12 hours or so and store it as variables so I can then display the information elsewhere.

Is this something I can do with PHP? Here is an example of the file:

ftp://polar.ncep.noaa.gov/pub/waves/latest_run/akw.46001.bull

many thanks

yes it can be done
you could try something like this:

<?php

$ftp = ftp_connect('polar.ncep.noaa.gov');
ftp_login($ftp, "anonymous", "");
ftp_get($ftp, 'akw.46001.bull', '/pub/waves/latest_run/akw.46001.bull', FTP_ASCII);
ftp_close($ftp);

$file = file('akw.46001.bull');
	
echo '<pre>';
	
foreach($file as $line)
	{	
		echo $line;
	}
	
echo '</pre>';
	
?>

this downloads the file, reads it into an array type variable ($file). And then it simply displays the contents of that variable.

hope this helps :)

yes it can be done
you could try something like this:

<?php

$ftp = ftp_connect('polar.ncep.noaa.gov');
ftp_login($ftp, "anonymous", "");
ftp_get($ftp, 'akw.46001.bull', '/pub/waves/latest_run/akw.46001.bull', FTP_ASCII);
ftp_close($ftp);

$file = file('akw.46001.bull');
	
echo '<pre>';
	
foreach($file as $line)
	{	
		echo $line;
	}
	
echo '</pre>';
	
?>

this downloads the file, reads it into an array type variable ($file). And then it simply displays the contents of that variable.

hope this helps :)

thanks for that hash, so then where would I start extracting the data from the file so it becomes individual variables.

Would I use some type of loop that goes through the text? For instance I eventually want to plot this data into a graph so I would be looking to create a XML file with different variables and there values i.e myvar1 = 5.6 myvar2 = 3.4 etc etc

thanks for that hash, so then where would I start extracting the data from the file so it becomes individual variables.

Would I use some type of loop that goes through the text? For instance I eventually want to plot this data into a graph so I would be looking to create a XML file with different variables and there values i.e myvar1 = 5.6 myvar2 = 3.4 etc etc

exactly, you iterate through the array then filter out the information you want using regular expressions with preg_match() or preg_match_all()

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.