php读取maxmind的二进制ISP文件

时间:2012-08-22 10:12:50

标签: php geolocation

我试图通过我的PHP函数读取ISP二进制文件(以FIPS 10-4格式编码)。但它以不可读的格式返回数据。

    $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; 
 }

任何人都可以如何将二进制文件的所有数据都加载到php字符串/数组中?

0 个答案:

没有答案