首頁 >後端開發 >php教程 >php,file操作,怎样实现一个readInt和readUTF

php,file操作,怎样实现一个readInt和readUTF

WBOY
WBOY原創
2016-06-06 20:11:531310瀏覽

比如我的writeInt和writeUTF是这样

<code>    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);
    }

</code>

readInt和readUTF怎么实现?

我尝试写,但是类型不对

<code>   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);#类型不对
    }</code>

回复内容:

比如我的writeInt和writeUTF是这样

<code>    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);
    }

</code>

readInt和readUTF怎么实现?

我尝试写,但是类型不对

<code>   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);#类型不对
    }</code>

http://blog.csdn.net/guotong1988/article...

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn