Home > Backend Development > PHP Tutorial > php,file操作,怎样实现一个readInt和readUTF

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

WBOY
Release: 2016-06-06 20:11:53
Original
1314 people have browsed it

比如我的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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

回复内容:

比如我的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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template