Jump to content

Reading Specific Data From A Text File?


anthonyc

Recommended Posts

Hello All,

 

Please excuse my lack of knowledge in advance, I'm a beginner but pick things up relatively quickly, and tend to do things by trial and error.

 

I would appreciate any help that anyone could offer with the following:

 

I would like to retrieve two pieces of data from a "text file" and use them to calculate a result from a function I have in javascript. An example of the javascript code is:

 

<script type="text/javascript">

function calculate() {

var drybulb = document.calc_form.drybulb.value;

var relhum = document.calc_form.relhum.value;

var answer = '';

if (drybulb !== '' && relhum !== '') {

answer = (0.567*drybulb*1) + (0.393 * (relhum*1/100 * 6.105 * Math.exp(17.27 * drybulb / (237.7 + drybulb*1)))) + 3.94;

}

document.calc_form.answer.value = answer;

return false;

}

</script>

 

Currently this is evaluated with entry from a simple html form, but I would like to have this performed "automatically".

 

 

The "text file" that I would like to access is here, not on my server:

 

http://www.bom.gov.au/fwo/IDV60901/IDV60901.94870.axf

 

I would like to extract the "air_temp" and "rel_hum" values under the [data] section for use in my function. I just need the "most recent" values (i.e. first), not all those contained in the file. This is a single record from that section (sorry for the mess this no doubt makes):

 

[data]

sort_order,wmo,name[80],history_product[80],local_date_time[80],local_date_time_full[80],aifstime_utc[80],air_temp,apparent_t,cloud[80],cloud_base_m,cloud_oktas,cloud_type[80],cloud_type_id,delta_t,dewpt,gust_kmh,gust_kt,lat,lon,press,press_msl,press_qnh,press_tend[80],rain_trace[80],rel_hum,sea_state[80],swell_dir_worded[80],swell_height,swell_period,vis_km[80],weather[80],wind_dir[80],wind_spd_kmh,wind_spd_kt

0,94870,"Moorabbin Airport","IDV60901","27/10:00pm","20120227220000","20120227110000",18.8,19.3,"Partly cloudy",510,3,"-",-9999,0.8,17.5,13,7,-38.0,145.1,1013.5,-9999.0,1013.5,"-","11.4",92,"-","-",-9999.0,-9999,"10","-","S",11,6

 

 

 

Would it be possible to obtain these values using PHP?, and if so any advice on how this could be done (noting my minimal knowledge) would be greatly appreciated.

 

Cheers.

 

Link to comment
Share on other sites

Here you go use the variables $airTemp and $relHum as you like in your javascript as you like

 

<?php
$data=file('http://www.bom.gov.au/fwo/IDV60901/IDV60901.94870.axf');
foreach ($data as $line) {
$info = explode(",", $line);
if ($info[0] == '0') { 
	$airTemp = $info[7];
	$relHum = $info[25];
	break;
}
}
echo "Air Temperature is: $airTemp<br/>";
echo "Relative Humidity is: $relHum %";
?>

Link to comment
Share on other sites

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.