Пользователь пока ничего не рассказал о себе

Наибольший вклад в теги

Все теги (3)

Лучшие ответы пользователя

Все ответы (1)
  • Как используя php получить массив объектов из SOAP Response от почты России?

    @alexnikitis
    function soap_parser($response)
    {
    	$res = array();
    	$xml = simplexml_load_string($soap);
    	
    	$xml->registerXPathNamespace('nspost', 'http://russianpost.org/operationhistory/data');
    	foreach ($xml->xpath('//nspost:OperationHistoryData/nspost:historyRecord') as $item)
    	{
    		$item->registerXPathNamespace('nspost', 'http://russianpost.org/operationhistory/data');
    		$index_x = $item->xpath('.//nspost:OperationAddress/nspost:Index');
    		$address_x = $item->xpath('.//nspost:OperationAddress/nspost:Description');
    		$date_x = $item->xpath('.//nspost:OperationParameters/nspost:OperDate');
    		$type_id_x = $item->xpath('.//nspost:OperationParameters/nspost:OperType/nspost:Id');
    		$type_x = $item->xpath('.//nspost:OperationParameters/nspost:OperType/nspost:Name');
    		$attr_id_x = $item->xpath('.//nspost:OperationParameters/nspost:OperAttr/nspost:Id');
    		$attr_x = $item->xpath('.//nspost:OperationParameters/nspost:OperAttr/nspost:Name');
    		$res[] = array(
    			'index' => (int)$index_x[0],
    			'address' => (string)$address_x[0],
    			'type_id' => (int)$type_id_x[0],
    			'type' => (string)$type_x[0],
    			'attr_id' => (int)$attr_id_x[0],
    			'attr' => (string)$attr_x[0],
    			'datetime' => date("Y-m-d H:i:s", strtotime((string)$date_x[0])),
    			'date' => date("Y-m-d", strtotime((string)$date_x[0])),
    			'time' => date("H:i:s", strtotime((string)$date_x[0])),
    			);
    	}
    	return $res;
    }
    Ответ написан
    2 комментария