A PHP type string is an 8-bit binary string, a char
sequence. He has no essence. Thus, for the most part endianness is not a problem in PHP.
If you need to prepare binary data in a specific form, use pack()
and unpack()
.
If you need to define the internal specification of a machine, you can use pack()
and unpack()
in the same way.
function isLittleEndian() { $testint = 0x00FF; $p = pack('S', $testint); return $testint===current(unpack('v', $p)); }
source share