//fwrite writes over, i.e. this example (win) may be misleading:
$file = 'e:/1.txt';
file_put_contents($file, 'hello'.chr(1).'0df6ac'.chr(0));
$fp = fopen($file, 'r+b');
$str = fread($fp, filesize($file));
$str = strtr($str, [chr(0)=>'']);
echo $str.PHP_EOL;//hello0df6ac
fseek($fp, 0);//указатель в начало
fwrite($fp, $str);
fclose($fp);
//add ftruncate ($ fp, 0);
//this will overwrite the file:
file_put_contents($file, 'hello'.chr(1).'0df6ac'.chr(0));
$fp = fopen($file, 'r+b');
$str = fread($fp, filesize($file));
$str = strtr($str, [chr(0)=>'']);
echo $str.PHP_EOL;//hello0df6ac
ftruncate ($ fp, 0);
fseek($fp, 0);//указатель в начало
fwrite($fp, $str);
fclose($fp);