Link to home
Create AccountLog in
Avatar of TedMorey
TedMoreyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP - PHP

I was wondering if someone would be able to convert the code below from classic ASP to PHP

    url = "https://www.pathfinder-xml.com/development/xml?Service=MetarGetCurrentConditionsForWeatherStationService&login.guid=49e3481552e7c4c9:2a2216a6:127f1bae19d:1566&login.accountID=#####&login.userID=#####&login.password=######&weatherStation.icaoCode=CYSK
    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.open "GET", url, false
    xmlhttp.send "" 

      set xDoc=xmlhttp.responseXML
set  ForecastNode=xDoc.selectSingleNode("MetarGetCurrentConditionsForWeatherStationResponse/MetarReport")
' this should give you the first EveningForecastNode.

temp3 = ForecastNode.getAttribute("Temperature")
temp3_c = (temp3-32)/1.8
'response.write "<li>High Celcius=" & ForecastNode.getAttribute("TemperatureHighCelcius")

    set xmlhttp = nothing
      
 response.Write(round(temp3_c,0))
ASKER CERTIFIED SOLUTION
Avatar of haloexpertsexchange
haloexpertsexchange
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
all variables start with $ and each statement is ended with a ;
also on line 7 I forgot the $ infront of xDoc.
How is this?

 $url = "https://www.pathfinder-xml.com/development/xml?Service=MetarGetCurrentConditionsForWeatherStationService&login.guid=49e3481552e7c4c9:2a2216a6:127f1bae19d:1566&login.accountID=#####&login.userID=#####&login.password=######&weatherStation.icaoCode=CYSK"; 
    set $xmlhttp = CreateObject("MSXML2.ServerXMLHTTP"); 
    $xmlhttp.$open "GET", $url, false; 
    $xmlhttp.$send ""; 
 
      set $xDoc=$xmlhttp.$responseXML;
set  $ForecastNode=$xDoc.$selectSingleNode["MetarGetCurrentConditionsForWeatherStationResponse/MetarReport"];
// this should give you the first EveningForecastNode.
 
$temp3 = $ForecastNode.$getAttribute["Temperature"];
$temp3_c = ($temp3-32)/1.8;
//response.write "<li>High Celcius=" & ForecastNode.getAttribute("TemperatureHighCelcius")
 
    set $xmlhttp = nothing; 
      
 echo round($temp3_c,0); 

Open in new window


I got it from this link and I have often used it and gotten accurate results - not all the time I might add.

http://www.design215.com/toolbox/translator/trans_login.php

Free registration is required to be able to use the tool.

Avatar of Beverley Portlock
From your code I would be looking to use either a SOAP client or SimpleXML

http://uk2.php.net/manual/en/class.soapclient.php

http://uk2.php.net/manual/en/function.simplexml-load-file.php

So you could try (UNTESTED)

<?php

$xml = simplexml_load_file("https://www.pathfinder-xml.com/development/xml?Service=MetarGetCurrentConditionsForWeatherStationService&login.guid=49e3481552e7c4c9:2a2216a6:127f1bae19d:1566&login.accountID=#####&login.userID=#####&login.password=######&weatherStation.icaoCode=CYSK");

// Test to see what came back
//
echo "<pre>";
print_r($xml);
echo "</pre>";

Open in new window


and then process with the SimpleXML functions