1. Home
  2. Computing & Technology
  3. PHP / MySQL

Read & Return Data From Files Into PHP

By Angela Bradley, About.com

3 of 5

Using file_get_contents () in PHP

File_get_contents () is similar to fread () in that it returns the entire contents of the file to a single string, however it can be done in a single line and performs better then fread ().
<?php
$file = file_get_contents ('YourFile.txt');
Echo $file;
?>
This little bit of code retrieves the data from YourFile.text and then echos it onto the page.

Index: Read & Return Data From Files Into PHP

  1. Reading File Data
  2. Using fread () in PHP
  3. Using file_get_contents () in PHP
  4. Using fgets () in PHP
  5. Using file () in PHP

3 of 5

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Advanced PHP
  5. File Get Contents - PHP File Get Contents - Tutorial File Get Contents

©2008 About.com, a part of The New York Times Company.

All rights reserved.