<?php
/** get palces api */
$url_getPlace = 'http://117.240.62.146/iiislifelineobapi/srvBkAPI.asmx/getPlace?frm=1&to=10000';
// Fetch the XML content from the URL
$xmlResponse_getPlace = file_get_contents($url_getPlace);
if ($xmlResponse_getPlace === false) {
    // Handle the error if the URL couldn't be fetched
    echo "Failed to fetch data from the URL.";
} else {
    // Use SimpleXML to parse the XML response
    $xml_getPlace= simplexml_load_string($xmlResponse_getPlace);
    if ($xml_getPlace === false) {
        // Handle XML parsing error
        echo "Failed to parse XML response.";
    } else {
        // Extract the JSON content from the XML element
        $jsonString_getPlace = (string)$xml_getPlace;
        // Decode the JSON string into a PHP array
        $data_getPlace = json_decode($jsonString_getPlace, true);
        if ($data_getPlace === null) {
        // Handle JSON decoding error
        echo "Failed to decode JSON data.";
        } else {
        // Now you can access and use the JSON data as needed
        // For example, to access the first item in the array:
        // $places = array();
        foreach ($data_getPlace as $value) {
            $places[] = $value['Place'];
            // echo "<option value='".$value['Place']."'>".$value['Place']."</option>";
        }
        // print_r($data_getPlace);
        // Use the extracted data as needed
        // echo "ID: $id, Name: $name";
        }
    }
}

// Encode the data as JSON and send it back to the client
header("Content-Type: application/json");
echo json_encode($places);
?>