Ciao a tutti spero che qualcuno tra di voi possa aiutarmi.
Avrei la necessità di inserire sul mio sito uno script molto semplice che attraverso le funzioni della libreria curl ottiene da msn weather un icona e la temperatura della città che vuoi in qualsiasi parte del mondo. Lo script è questo:
Codice PHP:
<?php
if (!$accid) {
$accid="ITXX0033";
}
$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";
# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);
# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);
# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}
## DEBUG
## print_r($MsnWeather);
#Convert Farrenheit to Celcius.
$MsnWeather['CTemp'] = round(((($MsnWeather['Temp']-32)/9)*5),0);
print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\">";
#Set $MsnWeather['CIcon'] if empty or null
if ($MsnWeather['CIcon']=="" || $MsnWeather['CIcon']=="NULL") {
$MsnWeather['CIcon'] = 44;
}
echo "<tr><td nowrap=\"nowrap\"><img align=\"absmiddle\" border=\"0\" src=\"http://www.mesnet.it/images/icons/". $MsnWeather['CIcon'] . ".gif\"> [b]". $MsnWeather['Temp'] ."°C [/b]</td></tr></table>";
?>
Come vedete non fà altro che collegarsi a un indirizzo dove come output si ha questo :
codice:
function makeWeatherObj() { this.swCity = "La Spezia"; this.swSubDiv = ""; this.swCountry = "Italy"; this.swRegion = "West Europe"; this.swTemp = "73"; this.swTempCel = Math.round((5/9)*(this.swTemp-32)); this.swCIcon = "30"; this.swWindS = "0"; this.swWindD = "CALM"; this.swBaro = "29.97"; this.swHumid = "65"; this.swReal = "74"; this.swUV = "2"; this.swVis = "6.21"; this.swLastUp = "07/03/2006 01:55:00"; this.swConText = "Partly Cloudy"; this.swFore = "2|3|4|5|6|07/03/2006|07/04/2006|07/05/2006|07/06/2006|07/07/2006|34|34|34|30|38|22|22|22|4|28|83|84|85|82|78|10|0|0|20|60|31|31|33|29|47|11|11|23|4|27|71|70|71|70|70|"; this.swAcid = "ITXX0033"; }
che varia a seconda del codice finale che nel mio caso è ITXX0033 che indica La Spezia.
Lo script non fà altro che eleaborare questo output tramite le funzioni di curl.
Il mio problema è il seguente.. l' hosting dove risiede il mio sito non supporta questa libreria, e (ho già chiesto) per il momento non possono installarla.
E' possibile utilizzare comunque questo script ( magari convertendolo con altre funzioni... - parlo da ignorante -
) ??
Qualcuno può aiutarmi o indicarmi la strada giusta ?
Grazie mille per le risposte