你可以用append(追加)方法打开文件,然后移动文件指针

解决方案 »

  1.   

    <?
    $fp=fopen("test.txt","r+");
    fwrite($fp,"123");
    fseek($fp,0);
    fwrite($fp,"4");
    fclose($fp);
    ?>不能用append.只有向上面这么做是可以的.文件最后是423
    但前提是一定要有test.txt文件,也就是在不存在test.txt的时候,会提示错误.
    你可以再加一个file_exist函数判断是否有test.txt.如果没有,就用w方式打开test.txt文件,再关闭,创建一个0字节的test.txt文件后,再继续上面的程序.
      

  2.   

    fseek函数是不是应该这样?
    fseek($fp,100L,0); 将位置指针移动到离文件头100个字节处
    fseek($fp,100L,1);……………………当前位置100个字节处
    fseek($fp,100L,2);……………………文件尾处向后退100个字节另
    用r+(append)方式不可以吗?我一直都是这么用的啊,下线试试先
      

  3.   

    fseek函数共有三个参数,前两个是必须要有的,第三个是可选.
    看这个:fseek
    (PHP 3, PHP 4 )fseek -- Seeks on a file pointer
    Description
    int fseek ( int fp, int offset [, int whence])Sets the file position indicator for the file referenced by fp.The new position, measured in bytes from the beginning of the file, is obtained by adding offset to the position specified by whence, whose values are defined as follows: SEEK_SET - Set position equal to offset bytes. 
    SEEK_CUR - Set position to current location plus offset. 
    SEEK_END - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.) If whence is not specified, it is assumed to be SEEK_SET. Upon success, returns 0; otherwise, returns -1. Note that seeking past EOF is not considered an error. May not be used on file pointers returned by fopen() if they use the "http://" or "ftp://" formats. Note: The whence argument was added after PHP 4.0.0. See also ftell() and rewind().