Example #1
0
function getWeather($varos_neve)
{
    $requestParams = array('CityName' => $varos_neve, 'CountryName' => '');
    $client = new SoapClient('http://www.webservicex.net/globalweather.asmx?WSDL');
    $response = $client->GetWeather($requestParams);
    $response_string = $response->GetWeatherResult;
    $response_xml = simplexml_load_string(mb_convert_encoding($response_string, 'utf-16'));
    $arr_resp = array('homerseklet' => (string) $response_xml[0]->Temperature, 'paratartalom' => (string) $response_xml[0]->RelativeHumidity, 'legnyomas' => (string) $response_xml[0]->Pressure);
    return $arr_resp;
}
Example #2
0
 /**
  *
  */
 public function indexAction($city, $country)
 {
     $wsdl = 'http://www.webservicex.com/globalweather.asmx?WSDL';
     $url = 'http://www.webservicex.com/globalweather.asmx';
     $client = new \SoapClient($wsdl, array('trace' => 1, 'exception' => 0, 'location' => $url, 'cache_wsdl' => WSDL_CACHE_NONE, 'soap_version' => SOAP_1_1));
     $inputparam = new \SoapVar('<ns1:GetWeather><ns1:CityName>' . $city . '</ns1:CityName><ns1:CountryName>' . $country . '</ns1:CountryName></ns1:GetWeather>', XSD_ANYXML);
     $return = $client->GetWeather($inputparam);
     $myresponse = $client->__getLastResponse();
     //return new Response(
     //'<html><body>Soap Esempio Response: <br>'.$client->__getLastResponse().'</body></html>'
     //);
     //$number = rand(1, $limit);
     return $this->render('estarRdaBundle:SoapEsempio:index.html.twig', array('myresponse' => $myresponse));
 }
Example #3
0
<?php

/*Este servicio esta leyendo el detalle del distrito*/
$country = $_GET['country'];
$city = $_GET['city'];
$client = new SoapClient("http://www.webservicex.com/globalweather.asmx?WSDL");
$result = $client->GetWeather(array('CountryName' => $country, 'CityName' => $city));
$xmlString = str_replace('<?xml version="1.0" encoding="utf-16"?>', '', $result->GetWeatherResult);
$objectResult = new SimpleXMLElement($xmlString);
echo '<li>';
echo $objectResult->Location;
echo '</li>';
echo '<li>';
echo $objectResult->Time;
echo '</li>';
echo '<li>';
echo $objectResult->Wind;
echo '</li>';
echo '<li>';
echo $objectResult->Visibility;
echo '</li>';
echo '<li>';
echo $objectResult->SkyConditions;
echo '</li>';
<?php

$client = new SoapClient("http://www.webservicex.net/globalweather.asmx?wsdl");
$params = new stdClass();
$params->CityName = 'Munich';
$params->CountryName = 'Germany';
$result = $client->GetWeather($params);
// Check for errors...
$weatherXML = $result->GetWeatherResult;
// some dirty workaround to change the label to utf-8
$weatherXML = preg_replace('/(<\\?xml[^?]+?)utf-16/i', '$1utf-8', $weatherXML);
// var_dump($weatherXML);
// write Result in xml file (filename as weather_Locationname.xml)
$filename = "xmls/weather_" . $params->CityName . ".xml";
$xmlfile = fopen($filename, "w");
fwrite($xmlfile, $weatherXML, 1000);
fclose($xmlfile);
// now get content of file by simplexml
$data = simplexml_load_file($filename);
$wLocation = $data->Location;
$wTime = $data->Time;
$wTimeFormats = explode("/", $wTime);
$wWind = $data->Wind;
$wVisibility = $data->Visibility;
$wSkyCond = $data->SkyConditions;
$wTemp = $data->Temperature;
$wDewpoint = $data->DewPoint;
$wHumidity = $data->RelativeHumidity;
$wPressure = $data->Pressure;
$formattedResult = "\n  <div>\n    <strong>" . $wLocation . "</strong>\n    <br/>" . $wTimeFormats[0] . "<br/>\n    <br/><span class='temp'>Temp.: " . $wTemp . "</span>\n    <br/>" . $wSkyCond . "\n    <br/>Humidity: " . $wHumidity . "\n    <br/>Pressure: " . $wPressure . "\n    <br/>Wind: " . substr($wWind, 0, -2) . "\n    <br/>Visibility: " . substr($wVisibility, 0, -2) . "\n    <br/>\n    <span><img src='images/weatherImages/" . trim($wSkyCond) . ".png' alt=''></span>\n  </div>";
// now display result
Example #5
0
<?php

require_once "userAuthentication.php";
$SessionID = $_GET['SessionKey'];
$auth = new UserAuth($SessionID);
$SessionResult = $auth->checkUserSession();
if ($SessionResult[0]) {
    $geolocation = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']));
    $APIURL = 'http://www.webservicex.net/globalweather.asmx/GetWeather' . '?CityName=' . urlencode($geolocation['geoplugin_city']) . '&CountryName=' . urlencode($geolocation['geoplugin_countryName']);
    $client = new SoapClient('http://www.webservicex.net/globalweather.asmx?wsdl');
    $params = array("CityName" => $geolocation['geoplugin_city'], "CountryName" => $geolocation['geoplugin_countryName']);
    $xml = $client->GetWeather($params)->GetWeatherResult or die("Cannot get weather results");
    $xml = mb_convert_encoding($xml, "UTF-16", "UTF-8");
    $XMLObject = simplexml_load_string($xml);
    echo json_encode($XMLObject);
    //Invalid XML given by API
    //http://stackoverflow.com/questions/6284548/document-labelled-utf-16-but-has-utf-8-content-in-entity-php-error
    //http://php.net/manual/en/function.mb-convert-encoding.php
    //http://stackoverflow.com/questions/14869227/php-simplexml-parsing-issue
    // $geolocation =  unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=8.8.8.8'));
    //$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $xml);
    // echo $XMLObject->Location;
} else {
    echo 'Authentication Failed.' . $SessionResult[1];
}
?>