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))
ASPPHP

Avatar of undefined
Last Comment
Beverley Portlock

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
haloexpertsexchange

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
haloexpertsexchange

all variables start with $ and each statement is ended with a ;
also on line 7 I forgot the $ infront of xDoc.
sammySeltzer

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.

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck