I’m trying to edit binary file while uploading to the server. My code opens file in binary mode, reads some bytes and does some mathematical operations. But I can’t find function that write binary data in binary form. fwrite(), fprintf(), sprintf() translate binary data into string and write their ASCII code. I tried chr(), ord(), bindec(), decbin(), hexdec(), dechex() and bin2hex() to convert string into binary format. Those functions work correctly while printing result on string. But when I try to write that result in a file, they automatically translates result into a string.
How can I stop translating binary data into string?
e.g. [code]$result = ord(‘1’) + ord(‘2’); /// 0x31 + 0x32
$fp = fopen(“sum.txt”, ‘wb’);
fprintf($fp, “%X”, $result);
fclose($fp);[/code]
This code writes 63 (0x36 0x33) in a file sum.txt.
What should I do so that answer 0x63 © will be written into file?
PS: I’m using PHP 5 on windows.