好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php读取本地文件操作函数 - php函数

php读取本地文件操作函数

在php中读取本地文件我们最常用的就是fopen与fread函数配置使用即可了,还有一些其它的像php file_get_contents可以读本地文件也可以读远程文件了,下面我们来一一介绍一下.

fopen() 函数,直接打开文件,例代码如下:

<?php  $file  =  "111.txt" ;  $fp  =  fopen ( $file , "r" );  if  ( $fp ){    while (! feof ( $fp )){     //第二个参数为读取的长度      $data  =  fread ( $fp , 1000);   }   fclose( $fp );  }  echo   $data ;  ?> 

file_get_contents() 函数把整个文件读入一个字符串中,例子代码如下:

<?php  echo   file_get_contents ( "test.txt" );  ?>  //输出:   This is a test file with test text. 

php读取本地文件夹文件,代码如下:

<?php  $dir  = opendir( '/movie' );  while (( $file  = readdir( $dir ))!=false){     if  ( $file != "."  &&  $file != ".." ) {        $ns  =  explode ( '.' ,  $file );       echo   $ns [0]; //开源代码phpfensi.com     }   }  closedir ( $dir );  ?>

查看更多关于php读取本地文件操作函数 - php函数的详细内容...

  阅读:36次