开发者

Get timestamp from base64Binary in PHP

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 tim开发者_如何学Cestamp 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?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜