public function get_data($country, $city) { $weather = new SoapClient($this->WSWEATHER); $params = array('CountryName' => $country, 'CityName' => $city); $response = $weather->getWeather($params); foreach ($response as $values) { if ($values !== 'Data Not Found') { $xml = preg_replace('/(<\\?xml[^?]+?)utf-16/i', '$1utf-8', $values); } else { $xml = '<?xml version="1.0" encoding="utf-8"?>'; $xml .= '<currentweather> <Location>Data Not Found</Location> <Time>Data Not Found</Time> <Wind>Data Not Found</Wind> <Visibility>Data Not Found</Visibility> <SkyConditions>Data Not Found</SkyConditions> <Temperature>Data Not Found</Temperature> <DewPoint>Data Not Found</DewPoint> <RelativeHumidity>Data Not Found</RelativeHumidity> <Pressure>Data Not Found</Pressure> <Status>Data Not Found</Status> </currentweather>'; } $data = simplexml_load_string($xml); } return $data; }