php 读取二进制文件
classHex
{
var$file;
var$hex;
function__construct($file)
{
$this->file=$file;
}
functiongethex()
{
$handle=fopen($this->file,'r')ordie('Haiipermessi?');
while(!feof($handle))
{
foreach(unpack('C*',fgets($handle))as$dec)
{
$tmp=dechex($dec);
$this->hex[].=strtoupper(str_repeat('0',2-strlen($tmp)).$tmp);
}
}
returnjoin($this->hex);
}
functionwritehex($hexcode)
{
foreach(str_split($hexcode,2)as$hex)
{
$tmp.=pack('C*',hexdec($hex));
}
$handle=fopen($this->file,'w+')ordie('Haiipermessi?');
fwrite($handle,$tmp);
}
}
?>
include('hex.class.php');
$obj=newHex('test');
$hexcode=$_POST['hexcode'];
if($hexcode)
{
$obj->writehex(trim($hexcode));
print'
0k.
';}
?>
=trim($obj->gethex())?>