Core Function BinaryToStr
From Sputnik Wiki
BinaryToStr( <binary-array>, <flag> )
Contents |
Description
Returns a new string containing the binary data as raw bytes.
Parameters
binary-array
The binary variable to use.
flag
Optional; Encoding to use.
Choices are:
"ASCII" = Each byte will directly be converted to a single character and returned as a string
"UTF8" = Similar to ASCII but uses 2 bytes of one for each character of the string it will make
"UNICODE" = Alias to UTF8 (or whatever Sputnik is using for Unicode strings)
Default: "ASCII"
Return Value
Returns a new string containing the binary data as raw bytes.
Remarks
Sputnik strings allow null terminators inside them so they can be used just like raw binary data this is useful since you can treat it as a string and use all the string functions but yet it's also binary.
Example
$binary = Pack("z0iii", "Hello World!", 100, 200, 300); echo "First binary variable printed BELOW\n"; printr($binary); echo "First binary variable printed ABOVE\n"; $binStr = BinaryToStr($binary); echo "String Content: $binStr\n"; echo "Second binary variable printed BELOW\n"; printr(BinaryFromStr($binStr)); echo "Second binary variable printed ABOVE\n"; /* Prints: First binary variable printed BELOW {BINARY:24} { [0] => 72 [1] => 101 [2] => 108 [3] => 108 [4] => 111 [5] => 32 [6] => 87 [7] => 111 [8] => 114 [9] => 108 [10] => 100 [11] => 33 [12] => 100 [13] => 0 [14] => 0 [15] => 0 [16] => 200 [17] => 0 [18] => 0 [19] => 0 [20] => 44 [21] => 1 [22] => 0 [23] => 0 } First binary variable printed ABOVE String Content: Hello World!d È ,☺ Second binary variable printed BELOW {BINARY:24} { [0] => 72 [1] => 101 [2] => 108 [3] => 108 [4] => 111 [5] => 32 [6] => 87 [7] => 111 [8] => 114 [9] => 108 [10] => 100 [11] => 33 [12] => 100 [13] => 0 [14] => 0 [15] => 0 [16] => 200 [17] => 0 [18] => 0 [19] => 0 [20] => 44 [21] => 1 [22] => 0 [23] => 0 } Second binary variable printed ABOVE */