This is 'C' Structure.
struct gross
{
char date[11];
char ac[128];
char type[5];
float mvalue;
float netraw;
float netfer;
char stat[128];
float firr;
float acb;
};
This is the content of binary file when compiled with GCC compiler.
12/12/1995 d us 12.23 34.12 90.12 fees 12 56.12
01/01/1998 a us 52.23 54.12 10.12 fees 92 16.12
31/12/1999 a us 52.23 54.12 10.12 fees 92 16.12
31/12/1999 d us 12.23 34.12 90.12 fees 12 56.12
01/01/2000 a us 52.23 54.12 10.12 fees 92 16.12
01/01/2000 z us 12.23 34.12 90.12 fees 12 56.12
31/12/2010 a us 52.23 54.12 10.12 fees 92 16.12
31/12/2010 d us 12.23 34.12 90.12 fees 12 56.12
This is the PHP coding to read the content of the above binary file.
echo "<table>";
while (!feof($f)) {
if ($s = fread($f, 292)) {
$nn = unpack('a11date/a128ac/a5type/fmvalue/fnetraw/fnetfer/a128stat/ffirr/facb', $s);
echo "<td>" . $nn[date] ."</td>";
echo "<td>" . $nn[ac] . "</td>";
echo "<td>" . $nn[type] . "</td>";
echo "<td>" . $nn[mvalue] . "</td>";
echo "<td>" . $nn[netraw] . "</td>";
echo "<td>" . $nn[netfer] . "</td>";
echo "<td>" . $nn[stat] . "</td>";
echo "<td>" . $nn[firr] . "</td>";
echo "<td>" . $nn[acb] . "</td>";
echo "</tr>";
}
}
echo "</table>";
fclose($f);
?>
This is the answer i got from the above code. I'm getting lot of garbage values is second and seventh field. And How to set precision for the float fields.
12/12/1995 d¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 12.229999542236 34.119998931885 90.120002746582 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 12 56.119998931885
01/01/1998 a¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 52.229999542236 54.119998931885 10.119999885559 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 92 16.120000839233
31/12/1999 a¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 52.229999542236 54.119998931885 10.119999885559 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 92 16.120000839233
31/12/1999 d¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 12.229999542236 34.119998931885 90.120002746582 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 12 56.119998931885
01/01/2000 a¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 52.229999542236 54.119998931885 10.119999885559 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 92 16.120000839233
01/01/2000 z¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 12.229999542236 34.119998931885 90.120002746582 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 12 56.119998931885
31/12/2010 a¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 52.229999542236 54.119998931885 10.119999885559 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 92 16.120000839233
31/12/2010 d¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 12.229999542236 34.119998931885 90.120002746582 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 12 56.119998931885
bin2hex(file_get_contents('table1.txt'));?bin2hex()though ...