首页 > php代码 > file_get_contents() 函数把整个文件读入一个字符串中

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

<?php
/*
 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 新加的。 
*/
$file = 'http://www.phprm.com/aa.txt';
//针对网络
if (file_get_contents($file)) {
    echo $file;
} else {
    echo $file, '不存在,请查检路径或文件名是否写正确了';
}
//针对本地址
$file = 'phprm.com.gif';
if (file_get_contents($file)) {
    echo $file; //输出内容
} else {
    echo $file, '无法打开';
}


文章链接:http://www.phprm.com/code/33ffadbdca291654fcdd2ed6a8838a64.html

随便收藏,请保留本文地址!

标签:none

发表留言