一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php读取本地文件操作函数

时间:2013-06-28 编辑:简简单单 来源:一聚教程网

fopen() 函数
直接打开文件

 代码如下 复制代码

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

file_get_contents() 函数把整个文件读入一个字符串中

例子

 代码如下 复制代码

echo file_get_contents("test.txt");
?>

输出:

This is a test file with test text.

php读取本地文件夹文件

 代码如下 复制代码

$dir = opendir('/movie');
while(($file = readdir($dir))!=false){
  if ($file!="." && $file!="..") {
    $ns = explode('.', $file);
    echo $ns[0];
  }
}
closedir($dir);

?>

热门栏目