0

I am trying to read a ISP binary file (coded in format FIPS 10-4) through my PHP function. But it returns the data in unreadable format.

    $filename = 'D:\xampp\htdocs\openx\var\jeet\GeoIPISP.dat';
    $handle = fopen($filename, "rb");
    $fsize = filesize($filename);
    $contents = fread($handle, $fsize);



   // iterate through each byte in the contents
   for($i = 0; $i < $fsize; $i++)
 { 
 // get the current ASCII character representation of the current byte
  $asciiCharacter = $contents[$i];
 // get the base 10 value of the current characer
 $base10value = ord($asciiCharacter);
 // now convert that byte from base 10 to base 2 (i.e 01001010...)
 $base2representation = base_convert($base10value, 10, 2);
 // print the 0s and 1s

 $base10value = base_convert($base2representation, 2, 10);  // => 132
 $ASCIICharacter = chr($base10value);               // => 'Z'
  echo  $ASCIICharacter; 
 }

Can anybody how i can get all the data of binary file into php string/array?

Jeet Singh
  • 402
  • 1
  • 5
  • 12
  • `file_get_contents` also http://www.maxmind.com/app/php – EaterOfCode Aug 22 '12 at 10:21
  • This thread may explain the format http://stackoverflow.com/questions/1294903/how-does-the-binary-dat-from-maxmind-work?rq=1 – Cups Aug 22 '12 at 10:39
  • @cups in referenced thread, they are passing a single IP and getting the value accordingly which is not my case. I need all the data which is present in binary file. – Jeet Singh Aug 22 '12 at 10:48

0 Answers0