binary - PHP read file as an array of bytes -
i have file written using java
program has array of integers written binary made loop on array , write using method
public static void writeint(outputstream out, int v) throws ioexception { out.write((v >>> 24) & 0xff); out.write((v >>> 16) & 0xff); out.write((v >>> 8) & 0xff); out.write((v >>> 0) & 0xff); }
i'm ask how read file in php
.
i believe code looking is:
$bytearray = unpack("n*",file_get_contents($filename));
update: working code supplied op
$filename = "myfile.sav"; $handle = fopen($filename, "rb"); $fsize = filesize($filename); $contents = fread($handle, $fsize); $bytearray = unpack("n*",$contents); print_r($bytearray); for($n = 0; $n < 16; $n++) { echo $bytearray [$n].'<br/>'; }
Comments
Post a Comment