php基础语法之文件操作

PHP文件操作

  • fopen: 打开文件或者 URL

    1
    resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )

  • fclose: 关闭一个已打开的文件指针

    1
    bool fclose ( resource $handle )
  • fread: 读取文件(可安全用于二进制文件)

    1
    string fread ( resource $handle , int $length )
  • fwrite: 写入文件(可安全用于二进制文件)

    1
    int fwrite ( resource $handle , string $string [, int $length ] )
  • file: 把整个文件读入一个数组中

    1
    array file ( string $filename [, int $flags = 0 [, resource $context ]] )
  • file_get_contents: 将整个文件读入一个字符串

    1
    string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
  • file_put_contents: 将一个字符串写入文件

    1
    int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )