views:

38

answers:

2

A webservice returns a timestamp field in base64Binary format. It looks like this in SOAP response:

<a:TimeStamp>AAAAAAMpI9Q=</a:TimeStamp>

PHP __soapCall, however, b64_decode()s that and I get a binary string looking like ')#▒'. How do I get actual timestamp out of this? I tried to unpack('L') it but it gives me Array([1] => 0) as a result. Is there really zero i.e. 1970-01-01 or have I missed something?

+2  A: 

This test program:

$b = "AAAAAAMpI9Q=";
$ts = base64_decode($b);
print_r(array_map("ord", str_split($ts)));

outputs:

Array
(
    [0] => 0
    [1] => 0
    [2] => 0
    [3] => 0
    [4] => 3
    [5] => 41
    [6] => 35
    [7] => 212
)

showing that the base64-encoded string gives you an 8-character string when unpacked. So presumably it represents a 64-bit integer, which might be signed or unsigned, and no, it isn't zero.

Given the values above it looks like the value is 53027796 - is that what you're expecting?

Richard Fearn
A: 

Thanks Richard, not sure if that timestamp is correct (it is somewhere like 1971-09-06) but at least now I know how to get it.

Andrey