php,file操作,怎样实现一个readInt和readUTF
程序员文章站
2024-02-01 19:19:16
...
比如我的writeInt和writeUTF是这样
function write_int($value)
{
$data = pack('N', $value);
fwrite($this->file, $data);
}
function write_utf($value)
{
$this->write_int(strlen($value));
fwrite($this->file,$value);
}
readInt和readUTF怎么实现?
我尝试写,但是类型不对
function read_int()
{
$data = fread($this->file, 4);
return unpack('N', $data);
}
function read_utf($value)
{
$l = $this->read_int();#unpack返回一个array不是int
return fread($this->file,$l);#类型不对
}
回复内容:
比如我的writeInt和writeUTF是这样
function write_int($value)
{
$data = pack('N', $value);
fwrite($this->file, $data);
}
function write_utf($value)
{
$this->write_int(strlen($value));
fwrite($this->file,$value);
}
readInt和readUTF怎么实现?
我尝试写,但是类型不对
function read_int()
{
$data = fread($this->file, 4);
return unpack('N', $data);
}
function read_utf($value)
{
$l = $this->read_int();#unpack返回一个array不是int
return fread($this->file,$l);#类型不对
}
http://blog.csdn.net/guotong1988/article...
上一篇: PHP实现的简单缓存类,php实现缓存_PHP教程
下一篇: 懂得中国银行的网上支付功能的麻烦解答下