Forum Home
Press F1
 
Thread ID: 66450 2006-02-23 08:28:00 Displaying data from another website John W (523) Press F1
Post ID Timestamp Content User
433118 2006-02-23 08:28:00 I was wondering if/how to go about getting, in this case the air temp for Dunedin, displayed on another website. Id like to include the Dunedin Temp from www.metservice.co.nz

Thanks
John W (523)
433119 2006-02-23 08:31:00 can't do, you could put this page www.cityofdunedin.com in an iframe, but messy, just better to have a link. netchicken (4843)
433120 2006-02-23 08:36:00 www.php.net maccrazy (6741)
433121 2006-02-23 09:53:00 Have a good read of this (www.metservice.co.nz)

Here is some fun php code.........

<?php
$url="www.metservice.co.nz
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$html = curl_exec ($ch);
curl_close ($ch);

$search_pattern = '/class="timeSpan">at&nbsp;(.*?)<\/td><\/tr>/';
preg_match($search_pattern,$html,$matches);
$date_time = $matches[1];
$search_pattern = '/Temperature:<\/td><td nowrap>&nbsp;(.)+&nbsp;/';
preg_match($search_pattern,$html,$matches);
$temp = $matches[1];
// dunedin's temperature is always wrong - fix it
$temp += 10;
echo "The last recorded temperature was $temp degrees Celsius, recorded at $date_time";
?>
gibler (49)
433122 2006-02-23 10:30:00 Unfortunately MetService can only provide you that service through their MetWeb package. You're not allowed to use the data on their site, other than for yourself. You can't display it on your website for others. Since linking to them, it'd be easy for them to know that you're doing this, due to the regular intervals your connection makes to their server.

You can however, use a free one from www.weatherreports.com, which only shows the high temperature, but it's better than nothing if you want to display the temperature.


Cheers,


KK
Kame (312)
1