<?php
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<root>
<apiKey>МОЙ КЛЮЧ</apiKey>
<calledMethod>getStatusDocuments</calledMethod>
<methodProperties>
<Documents>
<item>
<DocumentNumber>'.$value.'</DocumentNumber>
</item>
</Documents>
</methodProperties>
<modelName>TrackingDocument</modelName>
</root>'
;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.novaposhta.ua/v2.0/xml/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);
curl_close($ch);
$arrXml = gzuncompress($body);
$body ='';
curl_close($curl);
$XmlPos = mb_strpos($arrXml,'<?xml');
$XmlParse = (array)simpleXML_load_string(mb_substr($arrXml, $XmlPos),'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
$arrXml = '';
$json = @json_encode($XmlParse);
$XmlParse = '';
$json = @json_decode($json,1);
$arSuper = array();
$number = '';
$status = '';
foreach($json["data"] as $item){
$number = $item->Number;
$status = $item->Status;
$arSuper[] = array(
'number' => (string)$item['Number']['@attributes'],
'status' => (string)$item['Status']['@attributes'],
);
}
$json = '';
echo $number;
echo $status;
print_r($arSuper);