---
title: "file_get_contents() "
author: "yangyz1984"
date: "2010-08-25T20:55:22Z"
tags: []
categories: ["编程语言"]
slug: "file-get-contents"
draft: false
lastmod: "2010-08-25T20:56:05Z"
id: 747197
url: "https://yyzstudy.iteye.com/blog/747197"
---

## **定义和用法** file\_get\_contents() 函数把整个文件读入一个字符串中。 和 [file()](/php/func_filesystem_file.asp "PHP file() 函数") 一样，不同的是 file\_get\_contents() 把文件读入一个字符串。 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 新加的。 **说明** 对 *context* 参数的支持是 PHP 5.0.0 添加的。 **提示和注释** 注释：本函数可安全用于二进制对象。 **例子** `<?php echo file_get_contents("test.txt"); ?>` 输出： `This is a test file with test text.`