用php bin2hex函数读取bin文件

C.J*_*hns 2 php hex fopen bin

我正在尝试读取一个包含大量两个4字节数字的bin文件,我想要读取并转换为十六进制数字,然后打印到屏幕上....希望我有让我的头围绕这一点有点麻烦.这是我迄今为止阅读示例和文档的内容.

<?php

$handle = @fopen("files/bigbin1.bin", "r");
if ($handle) {
    while (!feof($handle)) {
        $hex = bin2hex($handle);
    }
    fclose($handle);

}

print_r($hex);
?>
Run Code Online (Sandbox Code Playgroud)

我95%肯定错误是将$ handle传递给tbin2hex ..但这是我第一次读取bin文件时我有点丢失.某些时候的总体目标是将bin文件读入数据库,但我只想弄清楚这个文件在屏幕上的样子.

GWW*_*GWW 6

<?php

$handle = @fopen("files/bigbin1.bin", "r");
if ($handle) {
    while (!feof($handle)) {
        $hex = bin2hex(fread ($handle , 4 ));
        print $hex."\n";
    }
    fclose($handle);

}

?>
Run Code Online (Sandbox Code Playgroud)

编辑:你应该避免使用@它可以使调试非常令人沮丧.