一、file_get_contents
1.定义
file_get_contents() 函数将指定 URL 的文件读入一个字符串并返回。
2.语法
file_get_contents(path, include_path, context, start, max_length)
- path:要读取的路径或链接。
- include_path:是否在路径中搜索文件,搜索则设为 1,默认为 false。
- context:修改流的行为,如超时时间,GET / POST 等。
- start:开始读文件的位置。
- max_length:读取文件的字节数。
3.示例
test.txt
-
<?php
-
echo "i'm a test php";
-
?>
index.php
-
<?php
-
$testTxt = file_get_contents('./test.txt');
-
var_dump($testTxt); // string(15) "i'm a test txt."
-
$ctx = stream_context_create(
-
array(
-
'http' => array(
-
'method' => 'get',
-
'timeout' => 30
-
)
-
)
-
);
-
$testTxt = file_get_contents('./test.txt&