Reputation: 581
I have a little problem :)
If I do it using SED or any hexadecimal editor, it works fine.
Can I open, edit (replace a string) and save a binary file using PHP?
Thank you very much!
Upvotes: 4
Views: 4050
Reputation: 42207
On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter. Then use fread and fwrite on the file.
<?php
$fp = fopen('binary_file.bin', 'w+b');
fwrite($fp, '1');
fclose($fp);
?>
Upvotes: 2
Reputation: 1416
You could read the file byte by byte, doing a binary comparation, and a byte to byte replacement. Write PHP code that look like C code :D
Upvotes: -2