Does anyone know of a way of checking within PHP if the script is running as either 32-bit or 64-bit? Currently I\'m using PHP 5.3.5.
Ideally I\'d like to write a f
A short way to get the number of bits.
strlen(decbin(~0));
How this works:
The bitwise complement operator, the tilde, ~, flips every bit.
@see http://php.net/manual/en/language.operators.bitwise.php
Using this on 0 switches on every bit for an integer.
This gives you the largest number that your PHP install can handle.
Then using decbin() will give you a string representation of this number in its binary form
@see http://php.net/manual/en/function.decbin.php
and strlen will give you the count of bits.
Here is it in a usable function
function is32Bits() {
return strlen(decbin(~0)) == 32;
}