PHP has a cast
(which until then I did not know), called binary
.
Example of Manual :
$binary = (binary)$string;
$binary = b"binary string";
According to the PHP Manual:
(binary) - convert to binary string
I saw that a user still posted the following:
Cast a string to binary using PHP < 5.2.1
(convert a string to binary in versions prior to PHP 5.2.1)
$binary = unpack('c*', $string);
With the test I performed in PHP 5.6, the result was as follows:
$string = "My String";
$binary = (binary)$string;
$binary = b"binary string";
var_dump($binary); // string(13) "binary string"
That is, returns the same value of the string (even with the cast for binary
).
The question is: is this functionality really available (being bug from my PHP) or will it just be a future implementation (as they say, "In PHP 6")?