gangslab
6/18/2015 - 11:28 AM

From http://stackoverflow.com/questions/16039751/php-pack-format-for-signed-32-int-big-endian

define('BIG_ENDIAN', pack('L', 1) === pack('N', 1));

function pack_int32s_be($n) {
    if (BIG_ENDIAN) {
        return pack('l', $n); // that's a lower case L
    }
    return strrev(pack('l', $n));
}
function pack_int32s_le($n) {
    if (BIG_ENDIAN) {
        return strrev(pack('l', $n));
    }
    return pack('l', $n); // that's a lower case L
}
function pack_double_be($n) {
    if (BIG_ENDIAN) {
        return pack('d', $n);
    }
    return strrev(pack('d', $n));
}
function pack_double_le($n) {
    if (BIG_ENDIAN) {
        return strrev(pack('d', $n));
    }
    return pack('d', $n);
}