Skip to content

Instantly share code, notes, and snippets.

@rouben
Created December 3, 2017 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rouben/ecf7f7300eb1d9c00b28ea33b9ac77b5 to your computer and use it in GitHub Desktop.
Save rouben/ecf7f7300eb1d9c00b28ea33b9ac77b5 to your computer and use it in GitHub Desktop.
Endianness check in PHP
<?php
/*
Taken from https://stackoverflow.com/questions/9744904/how-to-get-the-endianness-type-in-php
*/
function isLittleEndian() {
$testint = 0x00FF;
$p = pack('S', $testint);
return $testint===current(unpack('v', $p));
}
if (isLittleEndian()) {
echo "Little endian.\n";
}
else
{
echo "Big endian.\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment