1. 首页 > 科技

PHP file_get_contents()读入文件问题?

PHP file_get_contents()读入文件问题?

php中关于 file_get_contents的问题

file_get_contents(path,include_path,context,start,max_length);

path 必需。规定要读取的文件。

include_path 可选。如果也想在 include_path 中搜寻文件的话,可以将该参数设为 "1"。

context 可选。规定文件句柄的环境。context 是一套可以修改流的行为的选项。若使用 null,则忽略。

start 可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 新加的。

max_length 可选。规定读取的字节数。该参数是 PHP 5.1 新加的。

php中file_get_contents问题

$filename = "file.txt";

$content = file_get_contents($filename);

$contents = explode("\n",$content);

foreach($contents as $key=>$value){

echo $key,":",$value,"

";

}

?>

这是脚本内容

aaa

bbb

ccc

这是file.txt内容

可以正常读取!

你可以先设置路径啊

$filepath = "../a/b/a.txt";

$content = file_get_contents($filepath);就可以了啊!

php 使用file_get_contents()读取本地文件后,出现了这么一个警告,如何解决?

那实际上有没有读到内容?

如果有实际读到内容,可以用 @ 将错误屏蔽,如:

$path = 'xxxx.txt';

$content = @file_get_contents($path);

php 关于file_get_contents()的问题!

file函数 与 file_get_contents() 类似,不同的是 file() 将文件作为一个数组返回。数组中的每个单元都是文件中相应的一行,包括换行符在内。

所以亲,要注意有换行符,用trim()把换行符去掉试试