I am trying to open a file and write to the file as hex.
I have tried opening the file as a binary, which only inserts the array as a full string.
The other alternative i am trying at the moment, is using pack(), although i have never used this before.
Current code:
Code: Select all
$filename = 'phpHex.dat';
$Hex = $header.implode($Arr);
$HexArr = explode(" ",$Hex);
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w+b')) {
print "File: ($filename) can't be opened";
exit;
}
$i=0;
foreach($HexArr as $hex){
//$index = 0x.$i;
//fseek($handle, (binary)$i, SEEK_SET);
if(!fwrite($handle, pack('H*', $hex))){
print "Error writing to file";
}
//$i++;
}
fclose($handle);
}Would appreciate any suggestions.
~Weiry