首页  >  文章  >  后端开发  >  PHP 函数 file_get_contents 怎么用?

PHP 函数 file_get_contents 怎么用?

Guanhui
Guanhui原创
2020-06-24 14:02:122961浏览

PHP 函数 file_get_contents 怎么用?

PHP 函数 file_get_contents 怎么用?

在PHP中file_get_contents函数的作用是将整个文件读入一个字符串,其语法为“file_get_contents($filename) ”,返回值为读取出来的字符,使用方法只需将文件路径传入$filename即可。

使用示例

<?php
$homepage = file_get_contents(&#39;http://www.example.com/&#39;);
echo $homepage;
?>
<?php
// <= PHP 5
$file = file_get_contents(&#39;./people.txt&#39;, true);
// > PHP 5
$file = file_get_contents(&#39;./people.txt&#39;, FILE_USE_INCLUDE_PATH);
?>
<?php
// Read 14 characters starting from the 21st character
$section = file_get_contents(&#39;./people.txt&#39;, NULL, NULL, 20, 14);
var_dump($section);
?>
string(14) "lle Bjori Ro"

推荐教程:《PHP

以上是PHP 函数 file_get_contents 怎么用?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn