binaryfiles - Read Binary file records in php -
i have created binary file using c codings. structure of binary file.
struct emp { int eid,eage; char name[20],city[20]; }record;
using 'c' structure created binary file called "table1.txt"
now want show contents of file in web page using php. how can ?
<html> <head> <title>binary file</title></head> <body style="background-color:yellow"> <? $fp = fopen("table1.txt", "rb"); $read = fread($fp, 4); $n = unpack("i", $read); $data1 = fread($fp, 8); $nn = unpack("i",$data1); echo $number[1]; ?> </body> </html>
i have used above code. can read first field of file only. first record field employee id values '0'. page displays 0.
for strange reason, each data segment not 48 bytes expected 52 bytes.
$f = fopen('data.txt', 'rb'); while (!feof($f)) { // read 1 segment of 52 bytes if ($s = fread($f, 52)) { // unpack binary structure associative array print_r(unpack('ieid/ieage/a20name/a20city', $s)); } } fclose($f);
Comments
Post a Comment